assignment 6/.DS_Store __MACOSX/assignment 6/._.DS_Store assignment 6/sequence.cpp #include "sequence.h" // Constructor Sequence::Sequence() { numItems = 0; tailPtr = nullptr; headPtr = nullptr;...

1 answer below »
Do assignment based on assignment 6. NOTE: DO NOT copy code from online sources. I have been told by the instructor twice and received zero for doing that. If the expert can't do it by themselves just find another expert


assignment 6/.DS_Store __MACOSX/assignment 6/._.DS_Store assignment 6/sequence.cpp #include "sequence.h" // Constructor Sequence::Sequence() { numItems = 0; tailPtr = nullptr; headPtr = nullptr; cursor = nullptr; precursor = nullptr; } void Sequence::start() { if(numItems == 0) // empty sequence cursor = nullptr; else // Non-empty sequence cursor = headPtr; precursor = nullptr; } void Sequence::advance() { if(cursor == nullptr) return; if(cursor->next == nullptr) { precursor = nullptr; cursor = nullptr; } else { precursor = cursor; cursor = cursor -> next; } } bool Sequence::is_item() const { return cursor != nullptr; } Sequence::value_type Sequence::current() const { return cursor -> data; } Sequence::size_type Sequence::size() const { return numItems; } // Professor's solution to the // insert function 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) { tailPtr = new_node; } } else // inserting anywhere else { new_node->next = cursor; // tailPtr, headPtr and precursor don't change. precursor->next = new_node; } cursor = new_node; } __MACOSX/assignment 6/._sequence.cpp assignment 6/sequence.h #ifndef SEQ_H #define SEQ_H class Sequence { public: typedef int value_type; typedef int size_type; typedef struct node{value_type data; node* next;} node; Sequence(); // postcondition: The Sequence has been initialized to an empty Sequence. void start(); // postcondition: The first item in the Sequence becomes the current item (but if the // Sequence is empty, then there is no current item). void advance(); // precondition: is_item() returns true // Postcondition: If the current item was already the last item in the Sequence, then there // is no longer any current item. Otherwise, the new current item is the item immediately after // the original current item. void insert(const value_type& entry); // Postcondition: A new copy of entry has been inserted in the Sequence before the // current item. If there was no current item, then the new entry has been inserted at the // front. In either case, the new item is now the current item of the Sequence. void attach(const value_type& entry); // Not required this week // Postcondition: A new copy of entry has been inserted in the Sequence after the current // item. If there was no current item, then the new entry has been attached to the end of // the Sequence. In either case, the new item is now the current item of the Sequence. void remove_current(); // Not required this week // Precondition: is_item returns true. // Postcondition: The current item has been removed from the Sequence. If the item removed // was the last item in the Sequence, then there is now no current item. Otherwise, the item // that was after the removed item is now the current item. size_type size() const; // Postcondition: Returns the number of items in the Sequence. bool is_item() const; // Postcondition: A true return value indicates that there is a valid "current" item that // may be retrieved by the current member function (listed below). A false return value // indicates that there is no valid current item. value_type current() const; // Precondition: is_item() returns true // Postcondition: The current item in the Sequence is returned. private: int numItems; node* tailPtr; node* headPtr; node* cursor; node* precursor; }; #endif __MACOSX/assignment 6/._sequence.h assignment 6/last assignment 6.pdf __MACOSX/assignment 6/._last assignment 6.pdf
Answered 2 days AfterSep 30, 2021

Answer To: assignment 6/.DS_Store __MACOSX/assignment 6/._.DS_Store assignment 6/sequence.cpp #include...

Swapnil answered on Oct 03 2021
142 Votes
92509/Seq.cpp
#include "Seq.h"
void Seq::clr()
{
Root *c = headpointer;
while(c!= NULL)
{
c = c->n;
delete headpointer;
headpointer = c;
}
headpointer = tailpointer = NULL;
currentr = previouscurrentr = NULL;
s = 0;
}
void Seq::copy(const Seq &s)
{
Root *current = s.headpointer;
clr();
start();
while(current != NULL)
{
attach(current->data);
current = current->n;
}
}
Seq::~Seq()
{
clr();
}
Seq::Seq(const Seq &s):Seq()
{
copy(s);
}
void Seq::optr=(const Seq &s)
{
if(this == &s)
{
return;
}
copy(s);
previouscurrentr = s.previouscurrentr;
currentr = s.currentr;
}
Seq::Seq()
{
headpointer = NULL;
tailpointer = NULL;
currentr = NULL;
previouscurrentr = NULL;
s = 0;
}
void Seq::start()
{
previouscurrentr = NULL;
currentr = headpointer;
}
void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here