Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // zad4.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<cstdio>
- #include<cstdlib>
- using namespace std;
- class Elem {
- public:
- int l;
- Elem *nast;
- };
- class Stos {
- public:
- Elem *ostatni;
- //void init() { ostatni=NULL; }
- Stos ()
- {
- ostatni=NULL;
- cout<<"Wywolano konstruktor: "<<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; }
- /*void destroy() {
- while (! this->empty()) this->pop();
- }*/
- ~Stos()
- {
- while (! this->empty()) this->pop();
- cout<<"Wywolano destruktor: "<<this<<endl;
- }
- };
- void Wypisz(Stos& s)
- {
- Stos kopia;
- while (!s.empty())
- {
- cout << " " << s.top();
- kopia.push(s.top());
- s.pop();
- }
- cout<<endl;
- while (!kopia.empty())
- {
- s.push(kopia.top());
- kopia.pop();
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- //automatycznie:
- {
- Stos s1;
- s1.push(0);
- s1.push(1);
- s1.push(2);
- s1.push(3);
- s1.push(4);
- s1.push(5);
- s1.push(6);
- s1.push(7);
- s1.push(8);
- s1.push(9);
- Wypisz(s1);
- }
- //dynamicznie:
- Stos *s2=NULL;
- s2 = new Stos;
- delete s2;
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment