Question: Implement the insertFirst member function of the LinkedList class . Your header will be void LinkedList::insertFirst(int d) The job of insertFirst is to create a

Implement the insertFirst member function of the LinkedList class . Your header will be

void LinkedList::insertFirst(int d)

The job of insertFirst is to create a new Node with data equal to d and insert the Node at the front of the list. Don't forget to update headPtr and length. Also make sure you handle the case where the list is initially empty.

My incorrect attempt:

void LinkedList::insertFirst(int d){ int length; Node * nodeToInsert = new Node(value, headPtr); headPtr = nodeToInsert; length++;

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!