Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #define STOS_MAX 100
  5.  
  6. using namespace std;
  7.  
  8.  
  9. template<typename T>class Stos {
  10.  
  11.     private:
  12.         T data[STOS_MAX];
  13.         int size;
  14.  
  15.     public:
  16.         Stos() {    
  17.             size = 0;
  18.         }
  19.  
  20.         ~Stos() { }  
  21.  
  22.         int PobierzElementNaGorze() {
  23.             if (size == 0) {
  24.                 cout<<"Stos jest pusty!"<<endl;
  25.                 return -1;
  26.             }
  27.             return data[size-1];
  28.         }
  29.  
  30.         void Dodaj(int d) {
  31.  
  32.             if (size < STOS_MAX)
  33.                 data[size++] = d;
  34.             else
  35.                 cout<<"Stos jest pełen!"<<endl;
  36.         }
  37.  
  38.         void Zdejmij() {
  39.  
  40.             if (size == 0)
  41.                 cout<<"Stos jest pusty!"<<endl;
  42.             else
  43.                 size--;
  44.         }
  45. };
  46.  
  47. int main()
  48. {
  49.     Stos<int> obiekt;
  50.     obiekt.Dodaj(22);
  51.     obiekt.Dodaj(32);
  52.     cout<<obiekt.PobierzElementNaGorze()<<endl;
  53.     obiekt.Zdejmij();
  54.     cout<<obiekt.PobierzElementNaGorze()<<endl;
  55.     system("PAUSE");
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement