theme

" जीतने वाले छोड़ते नहीं और छोड़ने वाले जीतते नही "

Wednesday, July 6, 2011

programme of stack in c

#include
#include
int stack[10];
int top=-1;
void main()
{
int ch;
clrscr();
do
{
printf("**********MAIN MENU***********");
printf("\n1.push");
printf("\n2.pop");
printf("\n3.show");
printf("\n4.exit");
printf("\nenter your choice ");
scanf("%d",&ch);
switch(ch)
{
case 1 : push();break;
case 2 : pop();break;
case 3 : show();break;
case 4 : break;
default:printf("wrong choice");break;
}
}while(ch!=4);
}
push()
{
int n;
printf("enter the data");
scanf("%d",&n);
if(top==9)
{
printf("stack is overflow");
}
else
{
top++;
stack[top]=n;
}
}
pop()
{
if(top==-1)
{
printf("stack underflow");
}
else
{
top--;
}
}
show()
{
int i;
for(i=0;i<=top;i++)
{
printf("%d",stack[i]);
}
getch();
}

No comments:

Post a Comment