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 11Log into LinuxCopy files on csserver in /home/hwang/cs215/lecture11/*.*Practical Exam 1 review sheet postedReminder: Homework 5 due todayQuestions?Friday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 2OutlineSequence classIn-class ExerciseFriday, February 4 CS 215 Fundamentals of Programming II - Lecture 11 3Sequence ADTThe 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 ADTIn 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 ADTThe operations of the sequence ADT are:Default constructor that creates an empty sequencesize – a member function that returns the number of items in the sequencestart – 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 oneadvance – 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 ADTinsert – 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 ClassAs 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 6The 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 6Things 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 6This 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