Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- using namespace std;
- class stosik
- {
- public:
- int maxrzmiar;
- int *element;
- int wierzch =-1;
- void init ( int rozmiar)
- {
- maxrzmiar = rozmiar;
- element = new int[rozmiar];
- }
- void pop()
- {
- if (wierzch <= 0) cout << "Stos pusty" << endl;
- else wierzch--;
- }
- void destroy()
- {
- delete element;
- }
- void push( int cos)
- {
- if (wierzch == maxrzmiar)
- {
- cout << "Stos pelny" << endl;
- }
- else if (wierzch < maxrzmiar)
- {
- element[wierzch] = cos;
- wierzch++;
- }
- }
- int top()
- {
- if (wierzch > 0)
- {
- cout<<element[wierzch-1]<<endl;
- return element[wierzch - 1];
- }
- else cout << "stos jest pusty" << endl;
- }
- int full()
- {
- return maxrzmiar==wierzch;
- }
- int empty()
- {
- return wierzch==0;
- }
- };
- int main()
- {
- int x, i=0;
- stosik a,b;
- a.init( 10); b.init( 10);
- cout << "wprowadz 10 liczb na pierwszy stos" << endl;
- while(i<10)
- {
- cin >> x;
- a.push( x);
- i++;
- }
- i=0;
- while(i<10)
- {
- b.push( a.top());
- a.pop(); i++;
- }
- i=0;
- cout << "stos 2:"<<endl;
- while(i<10)
- {
- a.push(b.top());
- b.pop();
- i++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement