here you find the best simplest implement of programs

code_world

love programing and watch my all easy implement of program hope you like it

Friday, 5 May 2017

implement of stack using c



                     implement of stack using c  


#include<stdio.h>
#include<conio.h>
#define MAX 3
int st[MAX],top=-1;
void push(int st[]);
void pop(int st[]);
void display(int st[]);
void main()
{
int option;
clrscr();
p:
printf("main menu");
printf("\n1: insert");
printf("\n2: delete");
printf("\n3: display");
printf("\n4: exit");
printf("\nenter the value");
scanf("%d",&option);
switch(option)
{
 case 1: push(st);
goto p;
 case 2: pop(st);
goto p;
 case 3: display(st);
goto p;
 defult:exit(0);
 printf("%d",option);
 }
getch();
}
void push(int st[])
{
 int n;
 printf("enter the element ");
 scanf("%d",&n);
 if(top== MAX -1)
  {
    printf("stack overflow");
  }
  else
  {
    top++;
    st[top] = n;
    printf("%d",n);

  }
 }
 void pop(int st[])
  {
   int n;
   printf("enter the element");
   scanf("%d",&n);
   if(top==-1)
   {
     printf("stack is underflow");
   }
   else
  {
    n =st[top];
    top--;
  printf("%d",n);
  }
 }
 void display(int st[])
 {
  int i;
  if(top==-1)
  {
  printf("no element in  the stack");
  }
  else
  {
   for(i=top;i>=0;i--)
   printf("%d",st[i]);
   printf("\n");
   }
  }


Share:

Related Posts:

0 comments:

Post a Comment