Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- using namespace std;
- class Stos
- {
- public:
- int *tab,wierzch, rozmiar;
- void init ( int rozm)
- {
- tab=new int[rozm];
- rozmiar=rozm;
- wierzch=-1;
- }
- void destroy ()
- {
- delete [] tab;
- }
- void push(int rozm, int l)
- {
- if(wierzch>=rozm-1)
- cout<<"stos pelny"<<endl;
- else tab[++wierzch]=l;
- }
- void pop ()
- {
- if (rozmiar>=0)
- --rozmiar;
- else cout << "Stos jest pusty";
- }
- int top ()
- {
- return tab[wierzch--];
- }
- int empty ()
- {
- if(rozmiar==-1)
- return 1;
- else
- return 0;
- }
- bool full()
- {
- if(wierzch>= rozmiar-1)
- {
- return true;
- }
- else return false;
- }
- };
- int main ()
- {
- int rozmiar, liczba;
- Stos s1, s2;
- cout << "Podaj rozmiar stosu " << endl;
- cin >> rozmiar;
- s1.init(rozmiar);
- s2.init(rozmiar);
- cout << "Podaj liczby, jaka chcesz wstawic na wierzch" << endl;
- while(!s1.full())
- {
- cin >> liczba;
- s1.push(rozmiar, liczba);
- }
- for (int i=0; i<rozmiar; i++)
- s2.push( rozmiar,s1.top());
- cout << "Nowy stos:" << endl;
- for (int i=0; i<rozmiar; i++)
- cout << s2.top() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement