Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- class stog {
- public:
- int s[5], vrh;
- void ini() {
- vrh = 4;
- }
- void push(int x) {
- if(vrh == -1)
- cout << "stog je pun" << endl;
- else {
- s[vrh] = x;
- vrh--;
- }
- }
- int pop() {
- if(vrh == 4)
- cout << "stog je prazan" << endl;
- else
- vrh++;
- return s[vrh];
- }
- void ispis() {
- cout << endl;
- int i;
- for(i = vrh + 1; i <= 4; i++)
- cout << s[i] << endl;
- }
- };
- int main() {
- stog st;
- int izb, x;
- st.ini();
- do {
- cout << endl;
- cout << "1. push" << endl;
- cout << "2. pop" << endl;
- cout << "9. izlaz" << endl;
- cout << "___________" << endl;
- cin >> izb;
- cout << endl;
- if(izb == 1) {
- cout << "Unesi element: ";
- cin >> x;
- st.push(x);
- }
- if(izb == 2) {
- x = st.pop();
- cout << "iz stoga izlazi: " << x << endl;
- }
- st.ispis();
- } while(izb != 9);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment