Advertisement
d_usukhbaatar

Stack

Oct 15th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | Source Code | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. tepmlate<typename type>
  5. struct stack {
  6.     type data[100];
  7.     int sz;
  8.     stack() {
  9.         sz = 0;
  10.     }
  11.  
  12.     void push(type x) {
  13.         // code here!
  14.     }
  15.     void pop() {
  16.         // code here!
  17.     }
  18.     int size() {
  19.         // code here!
  20.     }
  21.     bool empty() {
  22.         // code here!
  23.     }
  24.     type top() {
  25.         // code here!
  26.     }
  27. };
  28.  
  29. int main() {
  30.     stack<int> s;
  31.     s.push(10);
  32.     s.push(20);
  33.     s.push(30);
  34.     cout << s.size() << endl;
  35.     cout << s.top() << endl;
  36.     s.push(40);
  37.     cout << s.top() << endl;
  38.     s.pop();
  39.     s.pop();
  40.     cout << s.top() << endl;
  41.    
  42.     while(!s.empty()) {
  43.         cout << s.top() << endl;
  44.         s.pop();
  45.     }
  46.     return 0;
  47. }
Tags: Stack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement