// This is lab test #5 version 2 TA Test Suite // You are to add three new recursive methods to the List class, found on the G: drive. // Information on the methods to add can be found below. // Your methods must work under all circumstances (feel free to add more test cases). // The third method must be recursive. // Submit files List.h and List.cpp. // // Note that this lab is worth a total of 15 (5 marks for each method), // but we will pretend that it's out of 10, i.e. you can get a maximum of 150%! #include "stdstuff.h" #include "List.h" int main () { List list, list2, list3, list4, empty, list5, list6; int i; for (i = 0; i < 15; i++) { list.insert ((i * i) - (8 * i) + 2); } list2.insert(5); list3=list; list4=list; list5.insert(0); list6.insert(4); list6.insert(4); //list.outputList (); // Method "countEqual" returns the number of values in the list that are equal to // the given value (here -5). If the list contains no values equal to the given value, it returns 0. // You are to add this method to class "List" (see above). // Note that your method should work properly in all circumstances, not just for this // particular list and value. Your method can be iterative or recursive. cout << "\nthe number of values in the list that are equal to -5 (should be 2): " << list.countEqual(-5) << "\n"; cout << "\nthe number of values in empty list equal to 0 (should be 0): " << empty.countEqual(0) << "\n"; cout << "\nthe number of values in [5] that are equal to -5 (should be 0): " << list2.countEqual(-5) << "\n"; cout << "\nthe number of values in [5] that are equal to 5 (should be 1): " << list2.countEqual(5) << "\n"; cout << "\nthe number of values in [4 4] that are equal to 4 (should be 2): " << list6.countEqual(4) << "\n\n"; // Method "insertAfterEvens" inserts the given value (here 5) after every node containing an // even value. "Even" refers to the contents of the node, not its position in the list. // If the list contains no even values, the method has no effect, i.e. the list is unchanged. // This method *never* quits. // You are to add this method to class "List" (see above). // Note that your method should work properly in all circumstances, not just for this // particular list. Your method can be iterative or recursive. list.insertAfterEvens(5); cout << "after inserting 5 after every even value the list is:\n"; list.outputList (); cout << "the above should be:\n"; cout << " 86 5 67 50 5 35 22 5 11 2\n"; cout << " 5 -5 -10 5 -13 -14 5 -13 -10 5\n"; cout << " -5 2 5\n\n"; empty.insertAfterEvens(0); cout << "after inserting 0 after every even value in the empty list (should be empty):\n"; empty.outputList (); list5.insertAfterEvens(10); cout << "\nafter inserting 10 after every even value in [0] (should be [0 10]):\n"; list5.outputList (); list2.insertAfterEvens(10); cout << "\nafter inserting 10 after every even value in [5] (should be [5]):\n"; list2.outputList (); list6.insertAfterEvens(-10); cout << "\nafter inserting -10 after every even value in [4 4] (should be [4 -10 4 -10]):\n"; list6.outputList (); // Method "isSameLengthAs" returns true if the two lists are the same length, false otherwise // (i.e. they are not the same length). Two lists are the same length if they contain the // same number of elements. // You are to add this method to class "List" (see above). // Note that your method should work properly in all circumstances, not just for these // particular lists. Your method must be recursive. if(list.isSameLengthAs(list2)) cout << "\nINCORRECT: list and list2 are the same length.\n"; else cout << "\nCORRECT: list and list2 are not the same length.\n"; if(list4.isSameLengthAs(list3)) cout << "\nCORRECT: list4 and list3 are the same length.\n"; else cout << "\nINCORRECT: list4 and list3 are not the same length.\n"; if(empty.isSameLengthAs(empty)) cout << "\nCORRECT: empty and empty are the same length.\n"; else cout << "\nINCORRECT: empty and empty are not the same length.\n"; if(list2.isSameLengthAs(list2)) cout << "\nCORRECT: list2 and list2 are the same length.\n"; else cout << "\nINCORRECT: list2 and list2 are not the same length.\n"; if(empty.isSameLengthAs(list2)) cout << "\nINCORRECT: empty and list2 are the same length.\n"; else cout << "\nCORRECT: empty and list2 are not the same length.\n"; if(list2.isSameLengthAs(empty)) cout << "\nINCORRECT: list2 and empty are the same length.\n"; else cout << "\nCORRECT: list2 and empty are not the same length.\n"; pause(); return 0; }