Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. template <class T>
  2. class Stos
  3. {
  4.     T* *tab;
  5.     int SIZE;
  6.     int top;
  7.  
  8. public:
  9.     Stos(int s = 5)
  10.     {
  11.         SIZE = s;
  12.         top = 0;
  13.         tab = new T*[SIZE];
  14.     }
  15.  
  16.     void push(T &ask)
  17.     {
  18.         if (top < SIZE)
  19.         {
  20.             tab[top] = new T(ask);
  21.             top++;
  22.         }
  23.         else
  24.         {
  25.             T* *qqq;
  26.             qqq= new T*[SIZE * 2];
  27.             for (int i = 0; i < top; ++i)
  28.                 qqq[i] = tab[i];
  29.             qqq[top] = new T(ask);
  30.             delete[] tab;
  31.             tab = qqq;
  32.             SIZE = SIZE * 2;
  33.             top++;
  34.         }
  35.     }
  36.     T pop()
  37.     {
  38.         if (top == 0)
  39.         {
  40.             cout << "Stos jest pusty" << endl;
  41.             getchar();
  42.             getchar();
  43.             return 0;
  44.         }
  45.         else
  46.         {
  47.             T tab1(*tab[--top]);
  48.             delete tab[top];
  49.             return tab1;
  50.         }
  51.     }
  52.  
  53.     void wyswietl()
  54.     {
  55.         for (int i = 0; i < top; i++)
  56.             cout << *(tab[i]) << " < ";
  57.         cout << endl << endl;
  58.     }
  59. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement