// This is lab test #5 version 2 // You are to add three new methods to the List class, found on the G: drive. // Information on the methods to add can be found below. // Note that the first two methods can be iterative or recursive. The third one (worth // 5 bonus marks) must be recursive. // Your methods must work under all circumstances (feel free to add more test cases). // 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; int i; for (i = 0; i < 15; i++) { list.insert ((i * i) - (8 * i) + 2); } list2.insert(5); list3=list; list4=list; 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: " << list.countEqual(-5) << "\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 (); // 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"; pause(); return 0; }