Right now my code only prints list in reverse direction and

Right now, my code only prints list in reverse direction and only first and last words of the list please help me to fix my list.cpp file so that it prints both forward and reverse directions both at same time in the output. YOU ONLY HAVE TO FIX THE LIST.CPP FILE. I HAVE ATTACHED THE IMAGE OF CURRENT OUTPUT PRODUCED BY THE PROGRAM.

I have already started working on this c program to print the list in forward and reverse order. I only need help to fix the code so that it prints in the forward direction. I asked my professor and his comments were that \" In your add function, for the \'normal\' case (the \'else\') branch, you
don\'t update \'last\' to point to the newly added node.
      if(first==0 && last==0)
      {
          first=newptr;
          last=newptr;
      }
      else
      {
          last->next=newptr;
     }

Current list.cpp file:

CURRENT OUTPUT:

Extra HINTS:

If you look at the code, you\'ll see that we keep two lists, one to print the text in forward order, and one to print the text in reverse order. The forward one is using our empty add() function, so nothing gets put into it. You\'ll fix that, as well as modifiying insert() and erase(). The reverse on works by inserting always at the head of the list, like a Stack.Functions insert(), erase(), and add() must be modified so that if the last node of the list changes, List::last must change, as well.

MAIN.CPP FILE:

LIST.H FILE:

#include list. h include next: i++) predptr predptr- next Set up new node Node newpotr Node newptr- payload item. (!predptr) are adding the first item in the list newptr next first newptr else if (position 0) We are inserting before the first node newpotr next first first newptr; else

Solution

change below statements:

else
      {
          last->next=newptr;
     }

used below statement instead.

else
{
last->next=newptr;
       last = newptr;
}

===========================================

previosuly the link was not made properly. Now it will work correctly.

Right now, my code only prints list in reverse direction and only first and last words of the list please help me to fix my list.cpp file so that it prints both

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site