Question: Write single linked list class member functions push_front, pop_front and front which work just like the back equivalents on the list code handout, only the

Write single linked list class member functions

push_front,

pop_front and front which work

just like the back equivalents on the list code handout, only the front of the list is used instead of the back. The function signatures and the basic modes of operation can be described as follows:

void push_front(const int &) { insert(0, din); }

void pop_front() {erase(0); }

const int &front() { node *p=findnode(0); return p->data; }

Your job is to implement each of these functions without calling other list member functions. Instead

make explicit use of pointers when relinking and accessing the nodes.

Submit only the code for these three functions.

Hint: Copy the code from the above mentioned list member functions. Remove any code not needed for the special case of operating at the front of the list, i.e., when inserting, removing and accessing the first node reachable from the head node of the list. Then clean-up and test the resulting code.

Hint: Sketch what you are trying to do on a piece of paper. Dont try to model it all in your head.

Please Help, Thanks a lot!

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!