// Oldham, Jeffrey D. // 2000Mar25 // CS1321 // Test the Deque Implementation #include #include // has EXIT_SUCCESS #include "deque.h" #include #include int main() { cout << "Hello, world.\n"; deque dq; string prompt = "Please enter an operation to perform:\n" "q: quit\n" "f: return front char\n" "Pf: push_front\n" "pf: pop_front\n" "b: return back char\n" "Pb: push_back\n" "pb: pop_back\n" "a: access 'th element\n"; string reply; cout << prompt; while (getline(cin, reply)) { if (reply.size() > 0) { char c = reply[0]; if (c == 'q' || c == 'Q') return EXIT_SUCCESS; else if (c == 'P' && reply.size() >= 3) { // push if (tolower(reply[1]) == 'f') dq.push_front(reply[2]); else dq.push_back(reply[2]); } else if (c == 'p' && reply.size() >= 2) { // pop if (tolower(reply[1]) == 'f') dq.pop_front(); else dq.pop_back(); } else if (c == 'f') cout << "The front is " << dq.front() << ".\n"; else if (c == 'b') cout << "The back is " << dq.back() << ".\n"; else if (c == 'a') cout << "The " << reply.substr(1) << "'th element = " << dq[strtoul(reply.substr(1).c_str(), static_cast(0),0)] << ".\n"; else cerr << "illegal character " << c << endl; } cout << dq << endl; } assert(false); // impossible to reach here return EXIT_FAILURE; }