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

Implement the getNodeAtPosition function of the LinkedList class.

Node * LinkedList::getNodeAtPosition(int position)

The job of this function is to return a pointer to the node the node at the given position. If the list is empty, position <= 0 or position > length, then the function should return the null pointer.

This is a helper function that can be used by various other member functions (e.g. insertAtPosition, removeAtPosition, getValue. setValue).

This is what I have so far, but it is wrong

Node * LinkedList::getNodeAtPosition(int position){ if(headPtr == NULL || position <= 0 || position > length) return NULL;

Node *temp = headPtr; for(int i=1; i

return temp; }

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!