// This is the test program and question description for Fall 2008 SYSC 2002 lab test #4 version #1 (for D1). // 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. // Note that your code must work for all lists, not just for the examples given here. // 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+1); list1.insert(i-1); list3.insert(10-2*i); } cout << "\nList1: "; list1.outputList(); cout << "\nList2: "; list2.outputList(); cout << "\nList3: "; list3.outputList(); // Method sumGreaterThan(n) returns the sum of the values in the given list that are greater than n. // Note that "greater than" refers to the contents (value) of the node *not* its position in the list. // If there are no values greater than n, this method returns 0. // This method does *not* change the list. cout << "\n\nThe sum of the values in list1 greater than 6 is: " << list1.sumGreaterThan(6) << ".\n\n"; cout << "The sum of the values in list2 greater than 0 is: " << list2.sumGreaterThan(0) << ".\n\n"; cout << "The sum of the values in list3 greater than -10 is: " << list3.sumGreaterThan(-10) << ".\n\n\n"; // Method hasValueLessThan(m) returns true if the list contains a value less than m, false otherwise. // Note that "less than" refers to the contents (value) of the node *not* its position in the list. // If there are no values in the list, this method returns false. // This method does *not* change the list. if (list1.hasValueLessThan(100)) cout << "List1 contains a value less than 100.\n\n"; else cout << "List1 does not contain a value less than 100.\n\n"; if (list2.hasValueLessThan(-100)) cout << "List2 contains a value less than -100.\n\n"; else cout << "List2 does not contain a value less than -100.\n\n"; if (list3.hasValueLessThan(-4)) cout << "List3 contains a value less than -4.\n\n\n"; else cout << "List3 does not contain a value less than -4.\n\n\n"; // Method hasDoubleValueAfter() returns true if the list contains a node directly followed by a node containing // double the value of the first node, and false otherwise. // If there are no values in the list, this method returns false. // This method does *not* change the list. if (list1.hasDoubleValueAfter()) cout << "List1 contains a node directly followed by one containing double its value.\n\n"; else cout << "List1 does not contain a node directly followed by one containing its double.\n\n"; if (list2.hasDoubleValueAfter()) cout << "List2 contains a node directly followed by one containing double its value.\n\n"; else cout << "List2 does not contain a node directly followed by one containing its double.\n\n"; if (list3.hasDoubleValueAfter()) cout << "List3 contains a node directly followed by one containing double its value.\n\n\n"; else cout << "List3 does not contain a node directly followed by one containing its double.\n\n\n"; } int main () { try { realMain (); } catch (exception &e) { // catches all uncaught exceptions cout << "\nException <" << e.what() << "> occurred.\n"; } pause (); return 0; }