Advertisement
Wojtekd

Z1

Dec 11th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Obiekt{
  4. };
  5.  
  6. class Stos
  7. {
  8.     private:
  9.         Obiekt** stos;
  10.         int count;
  11.         int rozmiar;
  12.    
  13.     public:
  14.         Stos(int);
  15.         void push(Obiekt*);
  16.         Obiekt* pop(); 
  17. };
  18. void Stos::push(Obiekt* obiekt) {
  19.     if(count + 1 > rozmiar) {
  20.             return;
  21.     }
  22.     stos[count] = obiekt;
  23.     count++;
  24. }
  25. Obiekt* Stos::pop() {  
  26.     if(count == 0)  {
  27.         return NULL;
  28.     }
  29.     Obiekt* temp = stos[count]; count--;
  30.     return temp;
  31. }
  32. Stos::Stos(int rozmiar) {
  33.     count = 0;
  34.     this->rozmiar = rozmiar;
  35.     stos = new Obiekt*[rozmiar];
  36. }
  37. int main()  {
  38.     Obiekt* obiekt1 = new Obiekt();
  39.     Obiekt* obiekt2 = new Obiekt();
  40.     Obiekt* obiekt3 = new Obiekt();
  41.     Stos stos(50);
  42.     stos.push(obiekt1);
  43.     stos.push(obiekt2);
  44.     stos.push(obiekt3);
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement