Question: Question 1 - 35 pts) Design and implement an algorithm to delete all the duplicate elements in a List ADT implemented as a singly linked

 Question 1 - 35 pts) Design and implement an algorithm todelete all the duplicate elements in a List ADT implemented as asingly linked list. You are given the code for the singly linkedlist-based implementation of a List ADT. The main function in this programis already setup to generate random integers and fill up the contents

Question 1 - 35 pts) Design and implement an algorithm to delete all the duplicate elements in a List ADT implemented as a singly linked list. You are given the code for the singly linked list-based implementation of a List ADT. The main function in this program is already setup to generate random integers and fill up the contents of the list (IntegerList). The deleteDuplicateElements() function is called on the IntegerList to delete the duplicate occurrences of all the elements in the list. Your task is to implement the deleteDuplicateElements() function in the singly linked list-based implementation of the List ADT. Your algorithm/implementation should run in time less than or equal to n? comparisons (which is the basic operation), where n is the number of elements in the list before the deletions. The main function is written in such a way that it will print the contents of the list before and after the deletions. You would test your code by entering 15 as the list size and 5 as the maximum value for any element. The list will be then filled with random integers in the range [1...5]. As ere are going to be integers in the list, it will be definitely the case that there will be more than one occurrence for one or more integers in the list. A sample output is shown below: Enter the maximum value in the list: 5 Enter the size for the list: 15 Before deletion: 53 2532211554315 After deletion: 53214 void setNextNodePtr (Nader nodcPtr #include Ninclude setext vodePtria); } Nade+ get HeadPtr return headPtr; ) baol isEmpty( if headPtr->getNextNodePtr) == 0) return true; return false; 1 void insert(int datal { Nodex currentNodePtr - leadPtr->getNextNodePtr(); Node prevNodePtr = headPtr while (currentNodePtr != X while (currentNodePtr != @}{ prevodePtr = currentNodePtr; currentNodePtr = currentNodePtr->getNextNodePtr(); } Nodex nemodePtr = new Node); nenNodePtr-ssetData(data); nenodePtr>setNextNodePtr(a): greyhodsPtr->setfextNodePtrincwtodePtr); } vaid insertAtIndex(int insert Index, int data) { Node> currentNode Ptr - headPtr->getNextNodePtr(); Nodex prevNodePtr = headPtr; int index = while (currentNodePtr != { if (index -- insert Index) break; arewindePtr currentNodePtr currentNodeptr currentNodePtr->getfvextNodeptr); indexH; } Node- newNodePtr - new Node); ne.NodePtr->setData(data); tionel :-* LMex Lad-Pr{currentNode2tr); prevNodePtr->setNextNodePtrinewodeptr); 1 int read( int read Index) { Nodex currentNodePtr = leadPtr->getNextNodePtr(); Nodex prevladePtr - headPtr int index = 0; while (currentNodePtr != 0){ if (index - read Index return currentNodePtr->getData(); prevodePtr = currentNodePtr currentNodePtr = currentNodePtr->getextNodeptr); index H+; } return -1; // an invalid value indicating // index is out of range 1 vaid nodifyElement(int nadifyIndex, int data){ Node currentNodePtr - headPtr->getNextNodePtr(); todo orolodotohodit Wederata() setData(data); return; } prevodePtr = currentNodePtr; currentNodePtr = currentNodeftr->getNextNadeptr); index:4; 1 vaid deleteElement(int delete Index}{ Nodex currentNodePtr = headPtr->getNextNodePtr(); Nodex prevNodePtr = headPtr; Node- nextNodetr - headptr; int index = 0 while (currentNodePtr ! 1f (index - deleteIndex) { nextNodePtr = currentNodePtr->getNextNodePtr(); break; 1 prevodePtr = currentNodePtr; currentNodePtr = currentNodePtr->getNextNodeptr); index; prevNodePtr->setNext NadetrinextNodePtr); ) void deleteDuplicateElenents) } vaid IterativePrint (K Node* currentNodePtr = headPtr->getNextNodePtr(); while (currentNodePtr != $){ } void IterativePrint Nodes currentNodePtr = leadPtr->getNextNodePtr(); while (currentNodePtr != 0X{ cout getData() getNextNodeptr); } cout maxva lue int listSize; 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 Databases Questions!