Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.3 kB
4
Indexable
Never
#include <iostream>

using namespace std;

class Stos
{
public:
    int w=-1;
    int *tab;
    int rozmiar;
    Stos(int r=100)
    {
        if(r==100)
        {
            cout<<"Wywolanie konstruktora domyslnego"<<endl;
            cout<<this<<endl;
        }
        else
        {
            cout<<"Wywolanie konstruktora z jednym parametrem"<<endl;
            cout<<this<<endl;
        }
        tab=new int[r];
        r=rozmiar;
    }
    ~Stos()
    {
        delete []tab;
        cout<<"Wywolanie destruktora"<<endl;
        cout<<this<<endl;
    }
    int push(Stos &s, int wartosc)
    {
        if(full())
            return 0;
        w++;
        return tab[w]=wartosc;
    }
    int pop()
    {
        if(empty())
            return 0;
        delete []tab;
        return w--;
    }
    int top()
    {
        if(empty())
            return 0;
        else
            return tab[w];
    }
    int full()
    {
        if(w>=rozmiar)
            return 1;
        else
            return 0;
    }
    int empty()
    {
        if(w==-1)
            return 1;
        else
            return 0;
    }
};

int main()
{
    Stos s1;
    s1.push(s1,15);
    cout<<s1.top()<<endl;
    return 0;
}