Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
4
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

/**** The basic structure***/
struct Stack{
   int items[10];
   int siz;
   Stack()
   {
       siz=0;
   }
};


/**** The empty function***/
bool empt(Stack &s)
{
    if(s.siz ==0)
        return true;
    return false;
}

/**** The full function***/
bool full(Stack &s)
{
    if(s.siz == 10)
        return true;
    return false;
}


/**** The push operation***/
void push(Stack &s, int N)
{
    if(full(s))
    {
        cout<<"The stack is full"<<endl;
        return;
    }

    s.items[s.siz]=N;
    s.siz = s.siz+1;
}

/**** The  pop operation***/
int pop(Stack &s)
{
    int temp = s.items[s.siz-1];
    s.siz = s.siz -1;
    return temp;
}

/**** The write pop operation***/
void write_pop(Stack &s)
{

    int temp = pop(s);
    cout<<temp<<endl;

}


int main()
{
    Stack s;
    push(s,5);
    push(s,7);
    push(s,-3);
    write_pop(s);
    push(s,9);
    while(!empt(s))
    {
       write_pop(s);
    }
    return 0;
}