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

Design a class IntList that contains a linked list of integers. The class should

ID: 3633425 • Letter: D

Question

Design a class IntList that contains a linked list of integers. The class should have member functions as follows:
– IntList(): Creates an empty list
– appendNode(int num): Adds a number to the end of the list
– deleteNode(int num): Delete a number from the list
– displayList(): Display the current contents of the list
– ~IntList(): Destroys the list
– selectionSort(): Performs selection sort on the list (in ascending order). Note that this sort operation must be performed directly on the linked list, not some separate copy of array. That is, you must use node pointers instead of array index to implement the algorithm.

In the main function
– Create an empty IntList object.
– Call appendNode function several times to put some numbers in random order.
– Then display the list (it should show unsorted numbers).
– Now perform selection sort on the list.
– Then display the list again (it should show sorted numbers).

Explanation / Answer

#include #include #include #include using namespace std; class linklist { private: struct node { int a; node *link; }*p; public: linklist(); void append( int num ); void add_as_first( int num ); void addafter( int c, int num ); void del( int num ); void display(); }; linklist::linklist() { p=NULL; } void linklist::append(int num) { node *q,*t,*o; if(p==NULL) { p=new node; p->a=num; p->link=NULL; } else { q=p; while(q->link!=NULL) { q=q->link; } o=new node; o->a=num; o->link=NULL; q->link=o; } } void linklist::add_as_first(int num) { node *q; q = new node; q->a = num; q->link = p; p = q; } void linklist::addafter( int c, int num) { node *q,*t,*o; q=p; int i; for(i=0;ilink; if(q== NULL) { coutlink; delete q; return; } r = q; while( q!=NULL ) { if( q->a == num ) { r->link = q->link; delete q; return; } r = q; q = q->link; } 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