// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition (C++)" by Clifford A. Shaffer. // Source code Copyright (C) 2007-2011 by Clifford A. Shaffer. // Full template version of find function template bool findt(List& L, Key K, E& it) { for (L.moveToStart(); L.currPos()& L, int K) { int it; for (L.moveToStart(); L.currPos() void lprint(List& L) { // We don't want to screw up the current position of the list int currpos = L.currPos(); L.moveToStart(); cout << "< "; int i; for (i=0; i\n"; L.moveToPos(currpos); // Reset the fence to its original position } // Here is test code to exercise the various methods template void ListTest(List& L1, List& L2, List& L3) { E1 temp1; E1 temp2; E2 temp3; lprint(L2); cout << "Size: " << L2.length() << endl; L2.clear(); L2.insert(new Int(1)); lprint(L2); cout << "Size: " << L2.length() << endl; L2.clear(); L2.append(new Int(1)); lprint(L2); cout << "Size: " << L2.length() << endl; L2.clear(); L2.append(new Int(1)); L2.moveToEnd(); lprint(L2); L2.clear(); // Test a bunch of list operations L2.append(new Int(1)); temp2 = L2.remove(); lprint(L2); L2.append(new Int(10)); lprint(L2); L2.append(new Int(20)); L2.append(new Int(15)); lprint(L2); L1.moveToStart(); L1.insert(new Int(39)); L1.next(); L1.insert(new Int(9)); L1.insert(new Int(5)); L1.append(new Int(4)); L1.append(new Int(3)); L1.append(new Int(2)); L1.append(new Int(1)); lprint(L1); L1.moveToStart(); if (! findt(L1, 3, temp1)) cout << "Value 3 not found.\n"; else cout << "Found " << temp1 << endl; lprint(L1); if (! findt(L1, 3, temp1)) cout << "Value 3 not found.\n"; else cout << "Found " << temp1 << endl; lprint(L1); L1.moveToStart(); if (! findt(L1, 29, temp1)) cout << "Value 29 not found.\n"; else cout << "Found " << temp1 << endl; if (! findt(L1, 5, temp1)) cout << "Value 5 not found.\n"; else cout << "Found " << temp1 << endl; L1.moveToStart(); if (! findt(L1, 5, temp1)) cout << "Value 5 not found.\n"; else cout << "Found " << temp1 << endl; L2.moveToStart(); if (L2.currPos()(L1, 4, temp1)) cout << "Value 4 not found.\n"; else cout << "Found " << temp1 << endl; L2.moveToStart(); if (L2.currPos()