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