Documente Academic
Documente Profesional
Documente Cultură
#include<stdio.h>
#include<conio.h>
#include<process.h>
#include<dos.h>
struct stack
{
int s[5];
int top;
};
if(st1->top<=-1)
{
printf("\n The stack is Underflow\n");
delay(2000);
exit(0);
}
else
{
x=st1->s[st1->top];
st1->top=st1->top-1;
printf("The element popped is:%d\n",x);
}
}
int ch,x,nv,p;
st.top=-1;
clrscr();
while(1)
{
printf("\n Enter 1 for push, 2 for pop, 3 for peep, 4 for change,5 for
exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter x:");
scanf("%d",&x);
push(&st,x);
break;
case 2:
pop(&st);
break;
case 3:
printf("Enter position from top:\n");
scanf("%d",&p);
peep(&st,p);
break;
case 4:
printf("Enter position from top which value to change:\n");
scanf("%d",&p);
printf("Enter new value:\n");
scanf("%d\n",&nv);
change(&st,p,nv);
break;
case 5:
Page 2