Question: Could i please get some help with this, it would mean a lot, thank you !! 2. The code below implements a simple Linked List

Could i please get some help with this, it would mean a lot, thank you !!

Could i please get some help with this, it wouldCould i please get some help with this, it wouldCould i please get some help with this, it would
2. The code below implements a simple Linked List for integers. This Linked List works much like a Stack, except that it allows insertions for any position in the list instead of only allowing you to push to the top. Modify this code using Templates so that it works for any data type (not just integers). Your solution should include: Seq.cpp (using the starter code below, modified to use templates) Seq.h Test.cpp (contains a main function for testing your code) Makefile Seq.cpp // Implementation of the simple Sequence class #include "Seq.h" #include #include using namespace std; // for cout, cin // Default constructor Seq::Seq(){ first = NULL; size = 0; // Copy Constructor Seq::Seq(const Seq& original )data = original.first->data; Node *pNewNode = first ; Node *poldNode = original.first->next; // Repeat until the entire list is copied while (pOldNode != NULL) pNewNode->next = new Node; pNewNode = pNewNode->next; pNewNode->data = pOldNode->data;; pOldNode = pOldNode->next; pNewNode->next = NULL; size = original.size;Seq::~SeqO){ Node *p = first; // Traverse the list deleting nodes while (p!= NULLX first = first->next; // hang on to the rest of the list delete p; // De-allocate memory p = first; // Go to next node first = NULL; size = 0; // Adds a node to the start of the sequence, making it the (new) first element void Seq::add(int x){ Node *p = new Node; //temporary node // Assign appropriate values to the new node p -> data = x; p -> next = first; // Make first point to the new node first = p; size+ +; // Inserts element x at the given position (or index) in the sequence void Seq::insertAt(int x, int pos){ Node *p; Node *newNode; // If pos is not a valid index, do nothing. if (pos > size){ return ; newNode = new Node; /ew node newNode->data = x; // Deal with case when item is to be inserted at the front if (pos == 0) newNode->next = first; first = newNode; }else{ // pos > 0 p = first; // Move to position BEFORE insertion point for(int i = 0; i next; // Insert node newNode->next = p->next; p->next = newNode; size+ +:// If data occurs in the sequence, removes the first occurrence and returns // true, otherwise returns false. bool Seq::remove(int x){ Node *p = first; Node *temp; // If sequence is empty, just return false. if (first = = NULLX return false; // Handle case where target is first else if (first->data = = x){ first = first ->next; delete p; //currently assigned head size--; return true; // Otherwise traverse the list, looking for data else{ while(p->next != NULLX // Check next node for target if(p->next->data = = xX temp = p->next; p->next = p->next->next; delete temp; return true; p = p->next; } return false; // Prints the entire sequence to the screen. // Most classes should not do their own I/O like this, because this // prevents a programmer using the class from controlling the I/O. // But, it can be convenient for debugging. void Seq::display(){ Node *p = first; cout data; // Print data p = p -> next; // Go to next node if (p != NULLX cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!