Advertisement
r1411

Стек

Jun 12th, 2021 (edited)
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define max 100
  5.  
  6. struct stek {
  7.     int top;
  8.     int S[max];
  9. };
  10.  
  11. void initStek(stek* st) {
  12.     st->top = -1;
  13. }
  14.  
  15. bool isEmpty(stek* st) {
  16.     return st->top == -1;
  17. }
  18.  
  19. void pushStek(stek* st, int x) {
  20.     if (st->top == max - 1) {
  21.         cout << "Стек переполнен!!!";
  22.     }
  23.     else {
  24.         st->S[++st->top] = x;
  25.     }
  26. }
  27.  
  28. int popStek(stek* st) {
  29.     return st->S[st->top--];
  30. }
  31.  
  32. void main() {
  33.     stek* st = new(stek);
  34.     initStek(st);
  35.  
  36.     pushStek(st, 1);
  37.     pushStek(st, 2);
  38.     pushStek(st, 3);
  39.  
  40.     popStek(st);
  41.     popStek(st);
  42.     popStek(st);
  43. }
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement