You must use this implementation. That means that you will have 5 data members, you won't have a header node, and precursor must be nullptr if cursor is nullptr. (What is a header node? If you don't know what it is, you probably aren't using it and shouldn't worry about it. It's not the same thing as a headPtr data member, which you WILL be using in this assignment.) You should implement nodes using the same technique shown in the lecture videos and in the examples in the written lesson. In other words, the should not be a node class; rather, a node struct should be defined inside the Sequence class. Many students make the mistake of thinking that this assignment will very closely track with the examples done in lecture. In this assignment perhaps more than any other so far I am expecting you to use the concepts taught in the lesson and text to implement a class that is very different from the ones done in the lessons and the text (instead of implementing a class that is pretty similar to the ones done in the lesson and text). I am providing my solution to the insert() function. This should make it easier to get started: you can use this insert() function and do all of this week's functions (default constructor, size(), start(), advance(), current(), and is_item()) and then write a client program to test what you have s far. void Sequence::insert (const value_type& entry) { node* new_node = new node; new_node->data= entry; numItems++; } if (cursor == headPtr || cursor == nullptr) { // insert at front (or into empty list). new_node->next = headPtr; // precursor remains nullptr. headPtr = new_node; if (numItems == 1) { } else { } tailPtr = new_node; new_node->next = cursor; precursor->next = new_node; cursor new_node; // inserting anywhere else // tailPtr, headPtr and precursor don't change.
Please just use main.cpp,sequence.cpp and sequence.h. It has provided the sample insert()function.
No documentation (commenting) is required for this assignment.
This assignment is based on an assignment from "Data Structures and Other Objects Using C++" by Michael Main and Walter Savitch.
Use linked lists to implement a Sequence class that stores int values.
Specification
The specification of the class is below. There are 9 member functions (not counting the big 3) and 2 types to define. The idea behind this class is that there will be an internal iterator, i.e., an iterator that the client cannot access, but that the class itself manages. For example, if we have a Sequence object named s, we would use s.start() to set the iterator to the beginning of the list, and s.advance() to move the iterator to the next node in the list.
(I'm making the analogy to iterators as a way to help you understand the point of what we are doing. If trying to think in terms of iterators is confusing, just forget about iterators and focus on following the specification below.)
What Is Due This Week
This is the first part of a two part assignment. In the next assignment you will be adding additional member functions to the class that you create in this assignment. I think this first part of the assignment is easier than the second part, so you may want to try to get an early start on next week's assignment. For this week, you are required to implement all of these functions except for attach() and remove_current(). You are also not required to implement the big-3.
Although we will just be testing your class using int values in the Sequence, you should define a value_type so that a programmer could easily edit the class to make it a Sequence that stores some other type of value. Note the Sequence is not a templated class.
Note: you should use assert() to halt execution if any of the preconditions below are not true



Trending now
This is a popular solution!
Step by step
Solved in 2 steps









