Guest User

Untitled

a guest
Jan 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #define size 50
  4. using namespace std;
  5.  
  6. void push(int i);
  7. int pop();
  8.  
  9. int *tos, *p1, stack[size];
  10.  
  11. int main()
  12. {
  13. setlocale(LC_ALL, "rus");
  14.  
  15. int value;
  16. tos = stack;
  17. p1 = stack;
  18.  
  19. do
  20. {
  21. cout << "Vvedite chislo:";
  22. cin >> value;
  23. if (value != 0) push(value);
  24. else cout << "Chislo na vershine steka ravno " << pop() << endl;
  25. } while (value != -1);
  26.  
  27. system("pause");
  28. return 0;
  29. }
  30.  
  31. void push(int i)
  32. {
  33. p1++;
  34. if (p1 == (tos + size))
  35. {
  36. cout << "Stek perepolnen" << endl;
  37. exit(1);
  38. }
  39. *p1 = i;
  40. }
  41.  
  42. int pop()
  43. {
  44. if (p1 == tos)
  45. {
  46. cout << "Stek ischerpan" << endl;
  47. exit(1);
  48. }
  49. }
Add Comment
Please, Sign In to add comment