// Oldham, Jeffrey D. // 2000Mar17 // CS1321 // Test Dynamic Array Implementations // Test pop_back(). #include #include // has EXIT_SUCCESS #include // helps detect memory leaks #include "dynamicArray.h" int main(int argc, char *argv[]) { mtrace(); // turn on memory leak detection if (argc != 2) { cerr << argv[0] << ": number-of-pushes\n"; throw "missing command-line argument"; } dynamicArray::length_pos nuPushes = strtoul(argv[1], static_cast(0), 0); // Do not check for errors. Bad! dynamicArray d; // Enlarge the array. for (dynamicArray::length_pos i = 0; i < nuPushes; ++i) d.push_back(2*i+1); // Perform the pop_back()s. cout << "i\td[0]\td[mid]\td[last]\tsize\n"; for (dynamicArray::length_pos i = nuPushes-1; i > 0; --i) { cout << i << ": " << d.pop_back(); cout << "\t" << d.get(0) << '\t' << d.get(i/2) << '\t' << d.get(i-1) << '\t' << d.size() << endl; } // Reenlarge the array. for (dynamicArray::length_pos i = 1; i < nuPushes; ++i) d.push_back(4*i+1); // Shrink the array. for (dynamicArray::length_pos i = nuPushes; i > 0; --i) cout << i << ": " << d.pop_back() << endl; cout << "size = " << d.size() << endl; return EXIT_SUCCESS; }