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
Get step-by-step solutions from verified subject matter experts
