Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>;
- using namespace std;
- class Stos
- {
- public:
- int *tab;//tablica przechowujaca elementy
- int wierzch, rozmiar;
- Stos(int rozmiar)
- {
- cout << "Konstruktor 1-parametrowy z rozmiarem " << rozmiar << " o adresie: " << &tab << endl;
- }
- Stos()
- {
- cout << "Konstruktor domyslny o adresie: " << &tab << endl;
- }
- void init(Stos& s,int rozm)
- {
- s.tab = new int[rozm];
- s.rozmiar = rozm;
- s.wierzch = -1;
- }
- void destroy(Stos& s)
- {
- delete[] s.tab;
- }
- void push(Stos& s, int l)
- {
- s.tab[++s.wierzch] = l;
- }
- void pop(Stos& s)
- {
- --s.wierzch;
- }
- int top(Stos& s)
- {
- return s.tab[s.wierzch];
- }
- int empty(Stos& s)
- {
- return s.wierzch == -1;
- }
- int full(Stos& s)
- {
- return s.wierzch == - 1;
- }
- ~Stos()
- {
- delete[]tab;
- cout << "Destruktor dla adresu: " << &tab << endl;
- }
- };
- int main()
- {
- Stos s1, s2;
- s1.init(s1, 10);
- s2.init(s2, 1000);
- s1.push(s1, 1);
- s1.push(s1, 2);
- s1.push(s1, 3);
- s1.push(s1, 1000);
- s1.pop(s1);
- s2.push(s2, 3);
- s2.push(s2, 8);
- s2.push(s2, 1);
- cout << "STOS s1:"<<endl;
- while (!s1.empty(s1))
- {
- cout << s1.top(s1) << endl;
- s1.pop(s1);
- }
- cout << "STOS s2:" << endl;
- while (!s2.empty(s2))
- {
- cout << s2.top(s2) << endl;
- s2.pop(s2);
- }
- s1.destroy(s1);
- s1.destroy(s2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement