Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int a[10000];
- int max;
- top=0;
- int push(int b)
- {
- a[top]=b;
- }
- int pop()
- {
- int temp;
- temp=a[top-1];
- a[top-1]=0;
- return temp;
- }
- void display()
- {
- int i;
- printf("\n\n");
- for(i=max-1;i>=0;i--){
- printf("%d\n",a[i]);
- }
- printf("\n\n");
- }
- int main()
- {
- int a,i,n,p;
- printf("Enter the size of stack:");
- scanf("%d",&max);
- for(i=0;;i++){
- printf("Enter 1 for push\nEnter 2 for pop\nEnter 3 for see stack\n");
- scanf("%d",&a);
- if(a==1){
- if(top>=max){
- printf("stack overflow\nCan't push\n");
- continue;
- }
- printf("\nEnter the number for push:\n");
- scanf("%d",&n);
- push(n);
- top++;
- }
- else if(a==2){
- if(top==0){
- printf("stack underflow\nCan't pop\n");
- continue;
- }
- p=pop();
- printf("\nThe poped item is %d\n",p);
- top--;
- }
- else{
- display();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement