CosminVarlan

c++ containers examples

Apr 7th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <queue> /// fifo
  4. #include <vector> /// fifo
  5. #include <stack>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. vector<int> v;
  11. queue<int> q;
  12. stack<int> s;
  13.  
  14. int main()
  15. {
  16.     /// also check this:    https://en.cppreference.com/w/cpp/container/vector
  17.     v.push_back(1);
  18.     v.push_back(2);
  19.     v.push_back(3);
  20.     for(int i=0; i<v.size(); i++)
  21.     {
  22.         cout << v[i] << ' '; /// O[1]
  23.     }
  24.     cout << endl;
  25.  
  26.  
  27.     q.push(1);
  28.     q.push(2);
  29.     q.push(3);
  30.     int k = q.size();
  31.  
  32.     for(int i=0; i<k; i++)
  33.     {
  34.         cout << q.front() << ' ';
  35.         q.pop();
  36.     }
  37.  
  38.     cout << endl;
  39.  
  40.  
  41.     s.push(1);
  42.     s.push(2);
  43.     s.push(3);
  44.     k = s.size();
  45.  
  46.     for(int i=0; i<k; i++)
  47.     {
  48.         cout << s.top() << ' ';
  49.         s.pop();
  50.     }
  51.  
  52.  
  53.  
  54.     return 0;
  55. }
Add Comment
Please, Sign In to add comment