Advertisement
LilChicha174

Untitled

Apr 21st, 2022
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. class CustomStack {
  7.         public:
  8.         void Stack() {
  9.             i = 0;
  10.         };
  11.  
  12.         int size() const{
  13.             return i;
  14.         }
  15.  
  16.         int top(){
  17.             return mData[i - 1];
  18.         }
  19.  
  20.         void push(int elem){
  21.             mData[i] = elem;
  22.             ++i;
  23.         }
  24.  
  25.         void pop(){
  26.             --i;
  27.         }
  28.  
  29.         bool empty() const{
  30.             if (i == 0) return true;
  31.             return false;
  32.         }
  33.  
  34.         void extend(int n){
  35.             i += n;
  36.         }
  37.  
  38.         private:
  39.         int mData[100];
  40.         int i;
  41. };
  42.  
  43.  
  44. int main() {
  45.     CustomStack Stack{};
  46.  
  47.     cout << Stack.empty();
  48.  
  49.     Stack.push(123);
  50.     Stack.push(342);
  51.     Stack.push(321);
  52.     Stack.push(324);
  53.  
  54.  
  55.     cout << Stack.size() << endl;
  56.     cout << Stack.empty() << endl;
  57.     Stack.extend(5);
  58.     cout << Stack.empty() << endl;
  59.  
  60.     Stack.extend(-5);
  61.  
  62.     cout << Stack.top() << endl;
  63.     Stack.pop();
  64.     cout << Stack.top() << endl;
  65.  
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement