Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Stos
- {
- public:
- int *tab;
- int max_wierzch;
- int wierzcholek = -1;
- int pop()
- {
- if (this->wierzcholek == -1) return 0;
- this->wierzcholek--;
- return 1;
- }
- int push(int liczba)
- {
- if (this->wierzcholek+1>=max_wierzch) return 0;
- this->tab[++this->wierzcholek] = liczba;
- return 1;
- }
- int top()
- {
- if (this->wierzcholek == -1) return 0;
- return this->tab[this->wierzcholek];
- }
- int empty()
- {
- if (this->wierzcholek == -1) return 1;
- return 0;
- }
- int full()
- {
- if (this->wierzcholek+1>=max_wierzch) return 1;
- return 0;
- }
- void init(int liczba)
- {
- this->tab = new int[liczba];
- this->max_wierzch = liczba;
- }
- void destroy()
- {
- delete [] this->tab;
- }
- };
- int main()
- {
- Stos stos1, stos2;
- stos1.init(10);
- stos2.init(10);
- int liczba;
- for (int i = 0; i < 10; i++)
- {
- cout << "Podaj liczbe nr " << i + 1 << ": ";
- cin >> liczba;
- stos1.push(liczba);
- }
- cout << endl;
- for (int i = 10; i > 0; i--)
- {
- stos2.push(stos1.top());
- cout << "Liczba nr " << i << ": " << stos1.top() << endl;
- stos1.pop();
- }
- for (int i = 0; i < 10; i++)
- {
- stos1.push(stos2.top());
- stos2.pop();
- }
- cout << endl;
- stos1.destroy();
- stos2.destroy();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement