Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void push (int s[], int &v, int val)
- {
- if (v < 255)
- s[++v] = val;
- }
- int top (int s[], int v)
- {
- return s[v];
- }
- void pop (int &v)
- {
- v = v - 1;
- }
- int main()
- {
- int s[256], n, i, v = 0, val;
- string p;
- cin >> n;
- for (i = 1; i <= n; i++)
- {
- cin >> p;
- if (p == "push")
- {
- cin >> val;
- push (s, v, val);
- }
- if (p == "pop")
- {
- pop(v);
- }
- if (p == "top")
- cout << top(s, v) << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement