Question
// It is C++ for your information class Node { public: Node* next; int data; }; class LinkedList { public: LinkedList(); ~LinkedList(); void add(int data);
// It is C++ for your information
class Node { public: Node* next; int data; };
class LinkedList { public: LinkedList(); ~LinkedList(); void add(int data); void InsertNth(int index, int data); void RemoveDuplicates(); Node* head;
};
LinkedList::LinkedList() { this->head = nullptr; }
LinkedList::~LinkedList() { //TODO WITH LAB INSTRUCTOR }
void LinkedList::add(int data) { Node* node = new Node(); node->data = data; node->next = this->head; this->head = node; }
void LinkedList::InsertNth(int index, int data) { //TODO //Good luck :) }
void LinkedList::RemoveDuplicates() { //TODO //Good luck :) }
Remove Duplicates of Sorted Linked List(Definitely Not Easy) A THE LINKED LIST IS SORTED Your code will only be tested on linked lists where the list is sorted in ascending order. These would be examples 1. 8-9 -> 10->11 2. 8- 8-9-9 3. 8- 8-10-> 42 4. empty Your job is to write a RemoveDuplicates() function which deletes any duplicate nodes from the list. Ideally, the list should only traversed once So if you were given the lists above, your resulting linked list should be 1. 8-9->10->11 2. 8->9 3. 8- 10- 42 4. empty Guidelines . Again, assume that the list is sorted like the examples above Make sure you consider this case 1- 1-1->1 . Do not mess with the function declaration Only code within the RemoveDuplicates function To test your code run make RemoveDuplicatesTest Checkoff In order to be checked off run make all. This will run all the tests at once! Once they all pass go see a CP or TA :DStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started