Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hello ! can you please help me with this in c++ programming ?? thank you !! Question 1 - 35 pts) Design and implement an

hello ! can you please help me with this in c++ programming ?? thank you !! image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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 r 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 there are going to be 15 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 #include #include #include #include #include #include using namespace std; // implementing the dynamic List ADT using Linked List class Node private: int data; Node* nextNodePtr; public: Node(){} void setData(int d) { data = d; } int getData(){ return data; } void setNextNodePtr(Node* nodePtr){ nextNodePtr = nodePtr; } Node* getNextNodePtr(){ return nextNodePt; } }; class List{ private: Node *headPtr; public: List(){ headPtr = new Node(); headPtr->setNextNodePtr(0); } Node* getHeadPtr(){ return headPtr; bool isEmpty(){ if (headPtr->getNextNodePtr() == 0) return true; return false; } void insert(int data){ Node* currentNodePtr = headPtr- >getNextNodePtr(); Node* prevNodePtr = headPtr; while (currentNodePtr != 0){ prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr- >getNextNodePtr(); } Node* newNodePtr = new Node(); newNodePtr->setData(data); newNodePtr->setNextNodePtr(0); prevNodePtr->setNextNodePtr(newNodePtr); } void insertAtIndex (int insertIndex, int data){ Node* currentNodePtr = headPtr- >getNextNodePtr(); Node* prevNodePtr = headPtr; int index = 0; while (currentNodePtr != 0){ if (index == insertindex) break; prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr- >getNextNodePtr(); index++; } Node* newNodePtr = new Node(); newNodePtr->setData(data); newNodePtr- >setNextNodePtr(currentNodePtr); prevNodePtr->setNextNodePtr(newNodePtr); } int read(int readIndex) { Node* currentNodePtr = headPtr- >getNextNodePtr(); Node* prevNodePtr = headPtr; int index = 0; while (currentNodePtr != 0){ if (index == readindex) return currentNodePtr->getData(); prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr- >getNextNodePtr(); index++; return -1; // an invalid value indicating // index is out of range } void modifyElement(int modifyIndex, int data){ Node* currentNodePtr = headPtr- >getNextNodePtr(); Node* prevNodePtr = headPtr; int index = 0; while (currentNodePtr != 0){ if (index == modifyIndex){ currentNodePtr->setData(data); return; } prevNodePtr = currentNodePtr; currentNodePtr = currentNodePtr- >getNextNodePtr(); } void IterativePrint(){ Node* currentNodePtr = headPtr- >getNextNodePtr(); while (currentNodePtr != 0){ cout getData() getNextNodePtr(); } cout > maxValue; int listSize; cout > listSize; cin >> maxvalue; int listSize; cout > listSize; // srand(time(NULL)); srand( static_cast unsigned int>(time(nullptr))); using namespace std::chrono; List IntegerList; l/high_resolution_clock::time_point t1 = high_resolution_clock::now(); for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions