Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class Stos
- {
- T* *tab;
- int SIZE;
- int top;
- public:
- Stos(int s = 5)
- {
- SIZE = s;
- top = 0;
- tab = new T*[SIZE];
- }
- void push(T &ask)
- {
- if (top < SIZE)
- {
- tab[top] = new T(ask);
- top++;
- }
- else
- {
- T* *qqq;
- qqq= new T*[SIZE * 2];
- for (int i = 0; i < top; ++i)
- qqq[i] = tab[i];
- qqq[top] = new T(ask);
- delete[] tab;
- tab = qqq;
- SIZE = SIZE * 2;
- top++;
- }
- }
- T pop()
- {
- if (top == 0)
- {
- cout << "Stos jest pusty" << endl;
- getchar();
- getchar();
- return 0;
- }
- else
- {
- T tab1(*tab[--top]);
- delete tab[top];
- return tab1;
- }
- }
- void wyswietl()
- {
- for (int i = 0; i < top; i++)
- cout << *(tab[i]) << " < ";
- cout << endl << endl;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement