Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int s[100];
- int stack_size=0, i = 0, max_stack_size = 10;
- void print_stack()
- {
- printf("current stack : ");
- for(i=0;i<stack_size;i++)
- {
- printf("%d ",s[i]);
- }
- printf("\n");
- }
- void push(int number)
- {
- printf("-->push(%d)\n",number);
- //do push
- if( stack_size <= max_stack_size ){
- s[stack_size] = number;
- stack_size++;
- print_stack();
- } else{
- printf("Stack Overflow\n");
- }
- }
- int pop()
- {
- printf("-->pop()\n");
- int num;
- //do pop
- if( stack_size > 0 ){
- s[stack_size - 1] = 0;
- stack_size--;
- print_stack();
- } else{
- printf("Stack Empty\n");
- }
- return num;
- }
- int main(){
- push(5);
- push(6);
- push(7);
- pop();
- push(4);
- pop();
- pop();
- push(5);
- push(6);
- push(7);
- push(5);
- push(6);
- push(7);
- push(5);
- push(6);
- push(7);
- push(5);
- push(6);
- push(7);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement