Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #define MAX 500
- struct stack{
- int stk[MAX] , t;
- void init(){ t = 0; }
- bool isempty(){ return !t; }
- bool isfull(){ return t == MAX - 1; }
- void push( int n ){
- if( t == MAX ) puts("Full!");
- else stk[t++] = n;
- }
- int pop(){
- if( !t ) puts("Empty!");
- return stk[--t];
- }
- };
- int main(){
- stack a;
- a.init();
- puts( a.isempty() ? "Empty stack!" : "Not empty" );
- a.push(1);
- a.push(2);
- a.push(3);
- a.push(4);
- a.pop();
- a.pop();
- a.push(100);
- printf( "%d\n" , a.pop() );
- printf( "%d\n" , a.pop() );
- printf( "%d\n" , a.pop() );
- printf( "%d\n" , a.pop() );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement