Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need to implement in c++ this non-List member function: void printList(List& theList, bool forward) is a non-member function that prints a list either forwards
I need to implement in c++ this non-List member function: void printList(List& theList, bool forward) is a non-member function that prints a list either forwards (by default -- from head to tail) when forward is true, or backwards (from tail to head) when forward is false. You must use your ListItr class to implement this function.
I attached my ListItr class I'm not sure how to implement this method help. This is one of the classes needed to implement a doubly linked list
#include "ListItr.h" #includeusing namespace std; ListItr:: ListItr(ListNode* theNode){ current = theNode; } bool ListItr:: isPastEnd() const{ if (current->next==NULL) return true; else return false; } bool ListItr:: isPastBeginning() const{ if (current->previous==NULL) return true; else return false; } void ListItr:: moveForward(){ if (!isPastEnd()) current=current->next; cout << current; } void ListItr:: moveBackward(){ if (!isPastBeginning()) current=current->previous; cout << current; } int ListItr:: retrieve() const{ return current->value; } void printList(List& theList, bool forward){ // if(forward==true){ // moveForward(); // } // if(forward == false){ // moveBackward(); // } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started