Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <functional>
  3. #include <iostream>
  4. #include "deque.cpp"
  5.  
  6. using namespace std;
  7. using namespace main_savitch_6B;
  8.  
  9. typedef int DataType;
  10. typedef deque<DataType> DequeType;
  11. typedef void(*CheckLambda)(DequeType &);
  12.  
  13. void run_check(const string &label, DequeType &dq, CheckLambda operation) {
  14.     cout << label << endl;
  15.     try {
  16.         operation(dq);
  17.         cout << dq << endl << endl;
  18.     } catch (int e) {
  19.         cout << "An exception occurred while running the check. Exception number: " << e << endl;
  20.         exit(e);
  21.     }
  22. }
  23.  
  24. int main() {
  25.  
  26.     DequeType dq;
  27.  
  28.     cout << "Hello, World!" << endl << endl;
  29.  
  30.     cout << "Initial State: " << endl;
  31.     cout << dq << endl << endl;
  32.  
  33.     run_check("pop_back() on empty deque", dq, [](DequeType &dq) -> void {
  34.         dq.pop_back();
  35.     });
  36.  
  37.     run_check("pop_front() on empty deque", dq, [](DequeType &dq) -> void {
  38.         dq.pop_front();
  39.     });
  40.  
  41.     run_check("push_front() on empty deque", dq, [](DequeType &dq) -> void {
  42.         dq.push_front(1);
  43.     });
  44.  
  45.     run_check("pop_bak() on deque of size 1", dq, [](DequeType &dq) -> void {
  46.         dq.pop_back();
  47.     });
  48.  
  49.     run_check("push_front() on empty deque (again)", dq, [](DequeType &dq) -> void {
  50.         dq.push_front(1);
  51.     });
  52.  
  53.     run_check("push_front() on deque of size 1", dq, [](DequeType &dq) -> void {
  54.         dq.push_front(2);
  55.     });
  56.  
  57.     run_check("adding extra entries using push_front()", dq, [](DequeType &dq) -> void {
  58.         dq.push_front(3);
  59.     });
  60.  
  61.     run_check("pop_front() on deque with a size greater than 1", dq, [](DequeType &dq) -> void {
  62.         dq.pop_front();
  63.     });
  64.  
  65.     run_check("pop_back() on deque with a size greater than 1", dq, [](DequeType &dq) -> void {
  66.         dq.pop_back();
  67.     });
  68.  
  69.     run_check("reset deque to be empty", dq, [](DequeType &dq) -> void {
  70.         dq = DequeType();
  71.     });
  72.  
  73.     run_check("push_back() on empty deque", dq, [](DequeType &dq) -> void {
  74.         dq.push_back(1);
  75.     });
  76.  
  77.     run_check("push_back() on deque of size 1", dq, [](DequeType &dq) -> void {
  78.         dq.push_back(2);
  79.     });
  80.  
  81.     run_check("push_back() on deque with a size greater than 1", dq, [](DequeType &dq) -> void {
  82.         dq.push_back(3);
  83.     });
  84.  
  85.     return EXIT_SUCCESS;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement