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

You are to implement a dynamic single Linked List structure. This List will be b

ID: 3652430 • Letter: Y

Question

You are to implement a dynamic single Linked List structure. This List will be based on the node definition given on the next page. Since you already know how to create classes, this should be a logical extension. Your goal is to create a Linked List class which contains

Explanation / Answer

//.h ile goes here #ifndef LINKED LIST_H #define LINKED LIST_H #include #include struct node { int data; node * next; }; class LinkedList { public: LinkedList(); void add(int A); bool empty(); // return true if the list is empty, otherwise return false void InsertInOrder(ElementType x);//insert a value x in numerical order in the list void Delete(int x); //if value x is in the list, remove x void Display();// Display the data values in the list private: node * first;//pointer to the first node in the list }; #endif //.cpp file starts here #include "Linked List.h" #include #include using namespace std; LinkedList::LinkedList() { first=NULL; } void LinkedList::add(int A) { if (first==NULL) { first=new node; first->data=A; first->next=NULL; } else { node *curr=first; node *prev=NULL; while (curr!=NULL) { prev=curr; curr=curr->next; } curr=new node; curr->data=A; curr->next=NULL; prev->next=curr; } } bool LinkedList::empty() { if (first==NULL) return true; else return false; } void LinkedList::Delete(int A) { node *curr=first; node *prev=NULL; bool flag=true; if (first->data==A) { first=first->next; delete first; flag=false; } else { while (flag && curr!=NULL) { if (curr->data==A) { prev->next=curr->next; delete curr; flag=false; } prev=curr; curr=curr->next; } if (flag==true) cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote