Stack(Data Structure) code

// Stack Code

#include<stdio.h>
#include<process.h>
int stack[5],top=-1;
main()
{
 int data,ch,i,x;
 printf("Menu\n1.Push\n2.POP\n3.Display\n4.Exit");
 do{
  printf("\nEnter choice no\n");
  scanf("%d",&ch);
 switch(ch)
 {
  case 1:
   printf("Enter Data\n");
   scanf("%d",&data);
   if(top==4)
   printf("Stack is Overflow");
   else
   {
    top++;
    stack[top]=data;
   }
   break;
   case 2:
    if(top==-1)
    printf("Stack is UnderFlow\n");
    else{
    x=stack[top];
    top--;
    printf("Deleted Data is = %d",x);}
    break;
    case 3:
     i=top;
     for(i=top;i>=0;i--)
     {
      printf("%d ",stack[i]);
     }
     break;
     case 4:
      exit(1);
      default:
       printf("Wrong choice try again\n");
 }
}while(ch!=4);
}

No comments:

Post a Comment