Problem 2
Implement the method push_back(), which is just a variant of method push_front(). Do not reinvent the wheel. The method push_back() does not require a search. Remember that fRoot is 12 o’ clock if the doubly-linked list nodes are viewed as a clock.
You can use #define P2 in Main.cpp to enable the corresponding test driver.
void testP2()
{
using StringList = List<string>;
string s1( "AAAA" );
string s2( "BBBB" );
string s3( "CCCC" );
string s4( "DDDD" );
string s5( "EEEE" );
string s6( "FFFF" );
cout << "Test of problem 2:" << endl;
StringList lList;
lList.push_front( s4 );
lList.push_front( s3 );
lList.push_front( s2 );
lList.push_front( s1 );
lList.push_back( s5 );
lList.push_back( s6 );
// iterate from the top
cout << "Bottom to top " << lList.size() << " elements:" << endl;
for ( StringList::Iterator iter = lList.rbegin(); iter != iter.rend(); iter-- ) {
cout << *iter << endl;
}
cout << "Completed" << endl;
}
The result should look like this. No errors should occur:
Test of problem 2:
Bottom to top 6 elements:
FFFF
EEEE
DDDD
CCCC
BBBB
AAAA
Completed
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.