Question: Implement the findPre function of the LinkedList class . Node * LinkedList::findPre(int d) The job of this function is to return a pointer to the

Implement the findPre function of the LinkedList class .

Node * LinkedList::findPre(int d)

The job of this function is to return a pointer to the node the precedes a node with data equal to d. If d only occurs in the head node or d doesn't occur in any node, then the function should return a pointer to the last node in the list. If the list is empty then the function should return the null pointer.

This is my current attemp, it is incorrect

Node * LinkedList::findPre(int d){ Node * pre = headPtr; for (int i = 1; i < position-1; i++) pre = pre->next; // how pre points to the node right before the one we want to remove. Node *temp = pre->next; pre->next = temp->next; }

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!