Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- using namespace std;
- class Elem {
- public:
- int l;
- Elem *nast;
- };
- class Stos {
- public:
- Elem *ostatni;
- Stos()
- {
- cout<<"Konstruktor"<<endl;
- ostatni=NULL;
- cout<<this<<endl;
- }
- void pop() {
- Elem* tmp=ostatni;
- ostatni=ostatni->nast;
- delete tmp;
- }
- void push (int l) {
- Elem* nowy=new Elem;
- nowy->nast=ostatni;
- nowy->l=l;
- ostatni=nowy;
- }
- int top() { return ostatni->l; }
- int full() {return 0; }
- int empty() {return ostatni==NULL; }
- ~Stos() {
- cout<<"Destruktor"<<endl;
- cout<<this<<endl;
- while (! this->empty())
- this->pop();
- }
- };
- Stos Wypisz(Stos &a) {
- Stos kopia;
- while (! a.empty())
- {
- // cout << " " << a.top();
- kopia.push(a.top());
- a.pop();
- }
- cout<<endl;
- while (! kopia.empty())
- {
- a.push(kopia.top());
- kopia.pop();
- }
- return kopia;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- Stos *s1 = new Stos();
- s1->push(10);
- s1->push(20);
- Wypisz(*s1);
- delete s1;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment