\\DATA STRUCTURE
\\TOPIC:MENUDRIVEN STACK IMPLEMENTATION
\\AUTHOR:DARSHIT VORA
#include < stdio.h >
#include < conio.h >
#include < process.h >
void push();
void pop();
void display();
int stack[10],top=-1,ch,i,ele;
char ans;
void main()
{
clrscr();
do
{
printf("1 - insert");
printf("\n2 - delete");
printf("\n3 - display");
printf("\n4 - exit");
printf("\nWhat do u wanna do");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:exit(0);
}
flushall();
printf("\nDo u wanna continue(y\n)");
flushall();
scanf("%d",&ans);
}while(ans=='y'||'Y');
getch();
}
void push()
{
if(top==-1)
printf("\n stack is empty");
if(top>=10)
{
printf("\nstack is full");
}
else
{
printf("\nEnter the elemnet u wanna insert");
scanf("%d",&ele);
top=top+1;
stack[top]=ele;
printf("\n%d is inserted",ele);
}
}
void pop()
{
printf("\n%d is deleted",stack[top]);
stack[top]=NULL;
top=top-1;
if(top==-1)
{
printf("\nstack is empty");
}
}
void display()
{
if(top==-1)
{
printf("\nStack is empty");
}
for(i=0;i < top;i++)
{
printf("\n%d",stack[i]);
}
}
\\TOPIC:MENUDRIVEN STACK IMPLEMENTATION
\\AUTHOR:DARSHIT VORA
#include < stdio.h >
#include < conio.h >
#include < process.h >
void push();
void pop();
void display();
int stack[10],top=-1,ch,i,ele;
char ans;
void main()
{
clrscr();
do
{
printf("1 - insert");
printf("\n2 - delete");
printf("\n3 - display");
printf("\n4 - exit");
printf("\nWhat do u wanna do");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
push();
break;
}
case 2:
{
pop();
break;
}
case 3:
{
display();
break;
}
case 4:exit(0);
}
flushall();
printf("\nDo u wanna continue(y\n)");
flushall();
scanf("%d",&ans);
}while(ans=='y'||'Y');
getch();
}
void push()
{
if(top==-1)
printf("\n stack is empty");
if(top>=10)
{
printf("\nstack is full");
}
else
{
printf("\nEnter the elemnet u wanna insert");
scanf("%d",&ele);
top=top+1;
stack[top]=ele;
printf("\n%d is inserted",ele);
}
}
void pop()
{
printf("\n%d is deleted",stack[top]);
stack[top]=NULL;
top=top-1;
if(top==-1)
{
printf("\nstack is empty");
}
}
void display()
{
if(top==-1)
{
printf("\nStack is empty");
}
for(i=0;i < top;i++)
{
printf("\n%d",stack[i]);
}
}
Comments
Post a Comment