Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <functional>
- #include <iostream>
- #include "deque.cpp"
- using namespace std;
- using namespace main_savitch_6B;
- typedef int DataType;
- typedef deque<DataType> DequeType;
- typedef void(*CheckLambda)(DequeType &);
- void run_check(const string &label, DequeType &dq, CheckLambda operation) {
- cout << label << endl;
- try {
- operation(dq);
- cout << dq << endl << endl;
- } catch (int e) {
- cout << "An exception occurred while running the check. Exception number: " << e << endl;
- exit(e);
- }
- }
- int main() {
- DequeType dq;
- cout << "Hello, World!" << endl << endl;
- cout << "Initial State: " << endl;
- cout << dq << endl << endl;
- run_check("pop_back() on empty deque", dq, [](DequeType &dq) -> void {
- dq.pop_back();
- });
- run_check("pop_front() on empty deque", dq, [](DequeType &dq) -> void {
- dq.pop_front();
- });
- run_check("push_front() on empty deque", dq, [](DequeType &dq) -> void {
- dq.push_front(1);
- });
- run_check("pop_bak() on deque of size 1", dq, [](DequeType &dq) -> void {
- dq.pop_back();
- });
- run_check("push_front() on empty deque (again)", dq, [](DequeType &dq) -> void {
- dq.push_front(1);
- });
- run_check("push_front() on deque of size 1", dq, [](DequeType &dq) -> void {
- dq.push_front(2);
- });
- run_check("adding extra entries using push_front()", dq, [](DequeType &dq) -> void {
- dq.push_front(3);
- });
- run_check("pop_front() on deque with a size greater than 1", dq, [](DequeType &dq) -> void {
- dq.pop_front();
- });
- run_check("pop_back() on deque with a size greater than 1", dq, [](DequeType &dq) -> void {
- dq.pop_back();
- });
- run_check("reset deque to be empty", dq, [](DequeType &dq) -> void {
- dq = DequeType();
- });
- run_check("push_back() on empty deque", dq, [](DequeType &dq) -> void {
- dq.push_back(1);
- });
- run_check("push_back() on deque of size 1", dq, [](DequeType &dq) -> void {
- dq.push_back(2);
- });
- run_check("push_back() on deque with a size greater than 1", dq, [](DequeType &dq) -> void {
- dq.push_back(3);
- });
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement