Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void push (int s[], int &v, int val)
  6. {
  7. if (v < 255)
  8. s[++v] = val;
  9. }
  10. int top (int s[], int v)
  11. {
  12. return s[v];
  13. }
  14. void pop (int &v)
  15. {
  16. v = v - 1;
  17. }
  18.  
  19. int main()
  20. {
  21. int s[256], n, i, v = 0, val;
  22. string p;
  23. cin >> n;
  24. for (i = 1; i <= n; i++)
  25. {
  26. cin >> p;
  27. if (p == "push")
  28. {
  29. cin >> val;
  30. push (s, v, val);
  31.  
  32. }
  33. if (p == "pop")
  34. {
  35. pop(v);
  36.  
  37. }
  38. if (p == "top")
  39. cout << top(s, v) << endl;
  40. }
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement