DOC PREVIEW
UE CS 215 - LECTURE NOTES

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 11OutlineSequence ADT 1Sequence ADT 2Sequence ADT 3Sequence ADT 4Sequence ClassIn-class Exercise 1In-class Exercise 2In-Class Exercise 3Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 1Lecture 11Log into LinuxCopy files on csserver in /home/hwang/cs215/lecture11/*.*Practical Exam 1 review sheet postedReminder: Homework 5 due todayQuestions?Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 2OutlineSequence classIn-class ExerciseFriday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 3Sequence ADTThe sequence ADT is described in Section 3.2 (pp. 124-132) of the textbook.A sequence is a container like a bag in that is stores a collection of items of the same type, and it can have duplicate items.A sequence differs from a bag in that the user can control the order of the items in the sequence. That is, a sequence has operations to add and remove items to and from specific places.Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 4Sequence ADTIn addition, a sequence provides operations to allow the user to access items one at a time in order. This technique is called an internal iterator. (In contrast to the STL iterators, which are external iterators. We'll see those later.)Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 5Sequence ADTThe operations of the sequence ADT are:Default constructor that creates an empty sequencesize – a member function that returns the number of items in the sequencestart – a member function that sets the current item position to the first item, if there is one.current – a member function that returns the current item, if there is oneadvance – a member function that will cause current( ) to return the next item in the sequence.is_item – a member function that returns true if there is an actual current item available; returns false otherwiseFriday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 6Sequence ADTinsert – a member function that receives an item and places it in the sequence in front of the current item, if there is one. If there was no current item, the item is inserted at the front of the sequence. The inserted item becomes the current item.attach – a member function that receives an item and places it in the sequence behind the current item, if there is one. If there is no current item, the item is added to the back of the sequence. The attached item becomes the current item.remove_current – a member function that removes the current item, if there is one. Afterwards, the item after the removed item becomes the current item, if there is such an item.Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 7Sequence ClassAs with the bag class, the sequence class is to be implemented using the partial array technique. In addition to the data array and the number of used positions, the sequence class will have an integer attribute current_index that keeps track of the current item. If there is a current item then it is at data[current_index]. If there is not a current item then current_index equals the number of used positions.Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 8In-class Exercise/Homework 6The class definition for the sequence class of double elements can be found in sequence1.h. It includes typedefs for value_type, size_type and defines the static member constant CAPACITY.sequence_test.cpp contains the interactive test program described in Section 3.3. A makefile Makefile.inclass11 has been provided for your convenience.You are to write the operation implementations in file sequence1.cpp.Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 9In-class Exercise/Homework 6Things to note:Pseudocode for some of the operations can be found on pp. 130-132.The start( ) and advance( ) functions modify the sequence state, but current( ) does not.For a sequence seq, the internal iterator pattern is used as follows:for (seq.start(); seq.is_item(); seq.advance()) // do something with seq.current()Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 10In-class Exercise/Homework 6This exercise constitutes Homework 6 (15 points) and is due on Friday, February 11, at 4:30pm.When you have completed this exercise, create a tarfile containing only sequence1.cpp and submit it electronically as usual.The submission system will only ensure that your file compiles successfully with the given files. It will not run your


View Full Document

UE CS 215 - LECTURE NOTES

Documents in this Course
Lecture 4

Lecture 4

14 pages

Lecture 5

Lecture 5

18 pages

Lecture 6

Lecture 6

17 pages

Lecture 7

Lecture 7

28 pages

Lecture 1

Lecture 1

16 pages

Lecture 5

Lecture 5

15 pages

Lecture 7

Lecture 7

28 pages

Load more
Download LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?