/* Program of stack using array*/ #include #define MAX 5 int top - TopicsExpress



          

/* Program of stack using array*/ #include #define MAX 5 int top = -1; int stack_arr[MAX]; main() { int choice; while(1) { printf("1.Push "); printf("2.Pop "); printf("3.Display "); printf("4.Quit "); printf("Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1 : push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(1); default: printf("Wrong choice "); }/*End of switch*/ }/*End of while*/ }/*End of main()*/ push() { int pushed_item; if(top == (MAX-1)) printf("Stack Overflow "); else { printf("Enter the item to be pushed in stack : "); scanf("%d",&pushed_item); top=top+1; stack_arr[top] = pushed_item; } }/*End of push()*/ pop() { if(top == -1) printf("Stack Underflow "); else { printf("Popped element is : %d ",stack_arr[top]); top=top-1; } }/*End of pop()*/ display() { int i; if(top == -1) printf("Stack is empty "); else { printf("Stack elements : "); for(i = top; i >=0; i--) printf("%d ", stack_arr[i] ); } }/*End of display()*/
Posted on: Sun, 14 Jul 2013 07:02:50 +0000

Trending Topics



Recently Viewed Topics




© 2015