// This is the test program and question description for a sample Fall 2008 SYSC 2002 lab test #4 lab test // Note that the three parts below are modified versions of exercises 4-6 at the end of Chapter 12 of the notes. // You are to write the three missing methods in the List class, plus any other helper functions or helper // methods that you like to solve the problems. Your solutions must be recursive. // The following code and the sample executable should make it clear as to what your methods must do. // IF YOUR SOLUTIONS ARE NOT RECURSIVE YOU WILL GET A VERY LOW MARK!! // Submit updated files List.h and List.cpp using the submit program provided. #include "stdstuff.h" #include "List.h" void realMain () { List list1, list2, list3; for (int i=10; i>0; i--) { list1.insert(i); list2.insert(i); list1.insert(i-1); list3.insert(10-i); } cout << "\nList1: "; list1.outputList(); cout << "\nList2: "; list2.outputList(); cout << "\nList3: "; list3.outputList(); // Method sumValues() returns the sum of the values in the given list. Note that // this refers to the contents (value) of the node *not* its position in the list. This method does // *not* change the list. cout << "\n\nThe sum of list1's values is: " << list1.sumValues() << ".\n\n"; cout << "The sum of list2's values is: " << list2.sumValues() << ".\n\n"; // Method numValues() returns the number of values in the given list. This method does // *not* change the list. cout << "\nThe number of values in list1 is: " << list1.numValues() << ".\n\n"; cout << "The number of values in list2 is: " << list2.numValues() << ".\n\n"; // Method isSortedAscending() returns true if the values in the given list are sorted in // ascending order (from the beginning to the end of the list), and false otherwise. // This method does *not* change the list. if (list2.isSortedAscending()) cout << "\nList2 is sorted in ascending order.\n\n"; else cout << "\nList2 is not sorted in ascending order.\n\n"; if (list3.isSortedAscending()) cout << "List3 is sorted in ascending order.\n\n\n"; else cout << "List3 is not sorted in ascending order.\n\n\n"; } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }