#include #include #include "list.h" void main() { list l1, l2; int x; // build a couple of lists for (x = 0; x < 30; x += 3 ) { l1.insertFirst( x ); } for (x = 0; x < 25; x += 2 ) { l2.orderedInsert( x ); } cout << "Original lists" << endl; cout << "list1: " << l1 << endl; cout << "list2: " << l2 << endl; cout << endl; // uncomment to observe the operations of the list list list l3( l1 ); // copy list 1 using a copy constructor list l4; // copy list 2 using an assignment operator l4 = l2; cout << "Copies of the lists" << endl; cout << "list3: " << l3 << endl; cout << "list4: " << l4 << endl; cout << endl; cout << "15 is " << ( l1.find( 15 ) ? "" : "not " ) << "in list 1" << endl; cout << "16 is " << ( l1.find( 16 ) ? "" : "not " ) << "in list 1" << endl; cout << endl; cout << "remove the first item (" << l1.removeFirst() << ") from list 1" << endl; cout << "remove the new first item (" << l1.removeFirst() << ") from list 1" << endl; cout << "list1: " << l1 << endl; cout << endl; cout << "remove item 12 from list 1" << endl; cout << "before: " << l1 << endl; l1.remove( 12 ); cout << "after: " << l1 << endl; cout << endl; // use a list iterator to move through the list listItr lt1( l1 ); cout << "list contents: "; for ( lt1.start(); lt1.more(); lt1.next() ) { cout << lt1.value() << " "; } cout << endl; cout << endl; /* // uncomment to test your code l3 = l1 + l2; cout << "Concatenated list (l1+l2): " << l3 << endl; cout << endl; l3.sort(); cout << "Ordered list: " << l3 << endl; */ // Test out some final exam functions // The [] operator cout << "l1[4] is "; if (l1[4]) cout << *(l1[4]) << endl; else cout << "out of range" << endl; cout << "l1[11] is "; if (l1[11]) cout << *(l1[11]) << endl; else cout << "out of range" << endl; // The unary + cout << "Sum of l1 is " << +l1 << endl; list l8; cout << "Sum of new list l8 is " << +l8 << endl; // Count nodes in list (it calls the private function) cout << "There are " << l1.countNodesInList() << " nodes in l1\n"; cout << "list1: " << l1 << endl; l1.mystery(); cout << "Post-mystery list1: " << l1 << endl; }