Create a Push Operation Using Array in C Language

#include<stdio.h>
#include<conio.h>
//#include<alloc.h>
int list[5],tos=-1,ch,value,size=4;
void main()
{
   void push();
   void display();
   clrscr();
   printf("\n1:Push Operation");
   printf("\n2:Display");
   printf("\n0:Exit");
   do
   {
      printf("\nEnter The Above Choice=>");
      scanf("%d",&ch);

      switch(ch)
      {
    case 1:
        push();
        break;
    case 2:
        display();
        break;
    case 0:
        exit(0);
    default:
         printf("\nPlease Enter The Above Choice");
      }
    }
    while(ch!=0);
}
void push()
{
   if(tos>=size)
   {
      printf("\nThe Stack is Overflow......");
      return;
   }
   else
   {
      printf("\nEnter The Element:->");
      scanf("%d",&value);
      tos=tos+1;
      list[tos]=value;
   }
}
void display()
{
  int i;
  if(tos==-1)
  {
     printf("\nThe Stack is Empty....");
     return;
  }
  else
  {
     for(i=0;i<=tos;i++)
     printf("\nThe Element is:->%d",list[i]);
  }
}
Create a Push Operation Using Array in C Language Create a Push Operation Using Array in C Language Reviewed by Unknown on 5:55:00 PM Rating: 5

No comments:

Powered by Blogger.