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

Here is an excerpt from the definition of a singly-linked list object represents

ID: 3826216 • Letter: H

Question

Here is an excerpt from the definition of a singly-linked list object represents a singly-linked list of integers. The implementation uses no dummy node, and the list end is indicated by the last node having NULL as its m next data member. The empty list i represented by m head and m tailbeing NULL. class LinkedIist public: creates an empty list LinkedList void push back int v); void unique bool nates (LinkedList& other const return dom (m head, other m head) private struct Node Node (int v, Node n) m value (v), m next (n) f) int m value Node m next points to first Node in the list Node m head points to last Node in the list Node* m tail bool dom (const Node pl const Node p2) const For this problem, will ask you write some function implementations. Be sure we to your code is syntactically correct as well as functionally correct. Notice that the Node type has no default constructor.

Explanation / Answer

//Below is the code test it

void unique()
{
Node *ptr1, *ptr2, *dup;
ptr1 = m_head;

while (ptr1 != m_tail && ptr1->next != m_tail)
{
ptr2 = ptr1;
while (ptr2->next != m_tail)
{
//duplicate then delete it
if (ptr1->data == ptr2->next->data)
{
//deleting the duplicate from list
               //copy the value to be deleted to the dup pointer
               //skip the dup pointer and point the current pointer to next of dup.
dup = ptr2->next;
ptr2->next = ptr2->next->next;
delete(dup);
}
else //move to next node
ptr2 = ptr2->next;
}
ptr1 = ptr1->next; //keep iterating till end of list
}
}

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