Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please solve C++ Extend the class linkedListType by adding the following operati

ID: 3630003 • Letter: P

Question

please solve C++

Extend the class linkedListType by adding the following operations:



a) Find and delete the node with the smallest info in the list. (Delete only the first occurrence and traverse the list only once.)


b) Find and delete all occurrences of a given info from the list. (Traverse the list only once.) Add these as abstract functions in the class linkedListType and provide the definitions of these functions in the class unorderedLinkedList. Also write a program to test these functions.

please show steps and explanation

Explanation / Answer

//LinkedList.h - defines a linked list #include using namespace std; template struct nodeType { T info; //some arb data - eg to contain a pointer to a class nodeType *link; }; template class linkedListType { public: void initializeList(); //function to initialize first element in list to zero //postcondition: first=NULL last=NULL bool isEmpty(); //function to see if list contains elements int Length(); //function to return the number of elements initialized in the list T firstItem(); //function to return the first item in the list T lastItem(); //function to return the last item in the list void appendItem(const T& newItem); //function to append an item to the list linkedListType(); //constructor ~linkedListType(); //destructor protected: nodeType *first; //pointer to first node nodeType *last; //pointer to last node int count; //stores number of items in the list }; template bool linkedListType::isEmpty() { return(first==NULL); } template linkedListType::linkedListType() { first=NULL; last=NULL; count=0; } template linkedListType::~linkedListType() { nodeType *temp; while(first!=NULL) { temp=first; first=first->link; delete temp; } last=NULL; count=0; } template linkedListType::Length() { return count; } template T linkedListType::firstItem() { if(!isEmpty()) { return first->info; //NB: return the first node's data member eg: return any object } else { return NULL; } } template T linkedListType::lastItem() { if(!isEmpty()) { return last->info; //NB: return the first node's data member eg: return any object } else { return NULL; } } template void linkedListType::appendItem(const T& newItem) { nodeType newNode; newNode->info=newItem; last->link=newNode; last=newNode; count++; }