Advertisement
LEGEND2004

stack queue deque

May 9th, 2024
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #pragma GCC optimize("O3")
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. #define int long long
  6.  
  7. signed main()
  8. {
  9.     ios_base::sync_with_stdio(0);
  10.     cin.tie(0);
  11.  
  12.     /*
  13.     stack<int> s;
  14.     s.push(x); // x elave eleyir
  15.     s.top(); // en son (ustdeki) element
  16.     s.pop(); // en son (ustdeki) elementi sil
  17.     s.size(); // olcusu
  18.     s.empty(); // bosdurmu?
  19.     */
  20.     /*
  21.     stack<int> s;
  22.     s.push(5);
  23.     s.push(7);
  24.     s.push(2); // 5 7 2
  25.  
  26.     cout << s.size() << '\n';
  27.  
  28.     cout << s.top() << '\n'; // 2
  29.     s.pop();
  30.     cout << s.top() << '\n'; // 7
  31.     s.pop();
  32.     cout << s.top() << '\n'; // 5
  33.     s.pop();
  34.     cout << (s.size() == 0) << '\n';
  35.  
  36.     while(!s.empty()){
  37.         cout << s.top() << '\n';
  38.         s.pop();
  39.     }
  40.  
  41. */
  42.     /*
  43.     queue<int> q;
  44.     q.push(x); // x elave eleyir
  45.     q.front(); // en ilk (soldaki) element
  46.     q.pop(); // en ilk (soldaki) element sil
  47.     q.size(); // olcusu
  48.     q.empty(); // bosdurmu?
  49.     */
  50.     /*
  51.     queue<int> q;
  52.     q.push(5);
  53.     q.push(7);
  54.     q.push(2); // 7 2
  55.  
  56.     cout << q.size() << '\n'; // 3
  57.     cout << q.front() << '\n'; // 5
  58.     q.pop();
  59.     cout << q.front() << '\n'; // 7
  60.     q.pop();
  61.     cout << q.front() << '\n'; // 2
  62.  
  63.  
  64.     while(!q.empty()){
  65.         cout << q.front() << '\n';
  66.         q.pop();
  67.     }
  68.     */
  69.     /*
  70.     deque<int> q;
  71.     q.size(); // olcusu
  72.     q.empty(); // bosdurmu?
  73.     //front ...   back
  74.     q.front(); // soldaki element
  75.     q.push_front(x); // x sola elave
  76.     q.pop_front(); // soldakini sil
  77.  
  78.     q.back(); // sagdaki element
  79.     q.push_back(x); // x saga elave
  80.     q.pop_back(); // en sagdaki sil
  81.     */
  82.     // big o notation
  83.     // O(1)
  84.     // + - * /
  85.     /*
  86.     // O(n)
  87.     for(int i = 1; i <= 2 * n; i++){
  88.         // O(1)
  89.     }
  90.  
  91.     // O(n * n)
  92.     for(int i = 1; i <= n; i++){
  93.         for(int j = 1; j <= n; j++){
  94.  
  95.         }
  96.     }
  97.     */
  98.  
  99.     // 2 * n * n + 5 * n --> O(n * n)
  100.     // 1 sec ~ 10^8 operations
  101.  
  102.     /*
  103.     deque<int> q;
  104.     q.push_front(5);
  105.     q.push_back(7);
  106.     q.push_front(2);
  107.     q.push_back(9);
  108.     q.push_front(1);
  109.     // front .. ..  back
  110.     // 1 2 5 7 9
  111.  
  112.     for(int i = 0; i < q.size(); i++){
  113.         cout << q[i] << " ";
  114.     }
  115.     cout << '\n';
  116.  
  117.     for(int i : q)
  118.         cout << i << " ";
  119.     cout << '\n';
  120.  
  121.     cout << q.front() << '\n'; // 1
  122.     q.pop_back();
  123.     cout << q.front() << '\n'; // 1
  124.     cout << q.back() << '\n'; // 7
  125.     q.pop_back();
  126.     cout << q.back() << '\n'; // 5
  127.     q.pop_front();
  128.     cout << q.front() << '\n'; // 2
  129.     cout << q.size() << '\n'; // 2
  130. */
  131. }
  132.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement