Friday, 24 May 2013

PUSH Operation on stack


#include<stdio.h>
#include<conio.h>
void main()
{
int stack[10];
int i,n,max=9,top=-1,item;
clrscr();
do
{
if(top==max)
{
 printf("\nOVERFLOW");
 printf("Press any key to continue");
 getch();
 break;
}
else
{
 top=top+1;
 printf("Enter the element to be inserted");
 scanf("%d",&item);
 stack[top]=item;
 printf("Stack elements are");
 for(i=top;i>=0;i--)
 {
 printf("\n%d",stack[i]);
 }
}
printf("\n\nDo you want to insert more element(Press 1 for Yes 2 for No");
scanf("%d",&n);
}
while(n==1);
}

No comments:

Post a Comment

full details in json
Proudly Powered by Blogger.
back to top