Guest User

Untitled

a guest
Jul 19th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Elem {
  7.  
  8. public:
  9.     int l;
  10.     Elem *nast;
  11. };
  12.  
  13. class Stos {
  14. public:
  15.  
  16.     Elem *ostatni;
  17.     Stos()
  18.     {
  19.         cout<<"Konstruktor"<<endl;
  20.         ostatni=NULL;
  21.         cout<<this<<endl;
  22.     }
  23.  
  24.     void pop() {
  25.         Elem* tmp=ostatni;
  26.         ostatni=ostatni->nast;
  27.         delete tmp;
  28.     }
  29.  
  30.     void push (int l) {
  31.         Elem* nowy=new Elem;
  32.         nowy->nast=ostatni;
  33.         nowy->l=l;
  34.         ostatni=nowy;
  35.     }
  36.     int top() { return ostatni->l; }
  37.  
  38.     int full() {return 0; }
  39.  
  40.     int empty() {return ostatni==NULL; }
  41.  
  42.     ~Stos() {
  43.         cout<<"Destruktor"<<endl;
  44.         cout<<this<<endl;
  45.         while (! this->empty())
  46.             this->pop();
  47.     }
  48. };
  49.  
  50. Stos Wypisz(Stos &a) {
  51.     Stos kopia;
  52.     while (! a.empty())
  53.     {
  54.     //  cout << " " << a.top();
  55.         kopia.push(a.top());
  56.         a.pop();
  57.     }
  58.     cout<<endl;
  59.     while (! kopia.empty())
  60.     {
  61.         a.push(kopia.top());
  62.         kopia.pop();
  63.     }
  64.     return kopia;
  65. }
  66.  
  67. int _tmain(int argc, _TCHAR* argv[])
  68. {
  69.     Stos *s1 = new Stos();
  70.     s1->push(10);
  71.     s1->push(20);
  72.     Wypisz(*s1);
  73.     delete s1;
  74.     system("pause");
  75.     return 0;
  76. }
Add Comment
Please, Sign In to add comment