//POP OPERATION of Stack
#include< stdio.h >
#include< conio.h >
//global declaration
int a[20],n,top,x,i;
void main()
{ clrscr();
printf("Enter Total Number of Elements = ");
scanf("%d",&n);
//initialise TOP
top=0;
//create and insert element in stack
while(top < n)
{ //check for Overflow
if(top > n)
{
printf("\nStack Full");
exit();
}
else
{
//enter element
printf("\nEnter Element a[%d] = ",top);
scanf("%d",&x);
a[top]=x;
top=top+1;
}
}
i=top-1;
//Traverse Stack
printf("\n***** Elements of Stack Are ***** \n");
while(i >= 0)
{
printf("_____\n");
printf("| %d |\n",a[i]);
i=i-1;
}
printf("_____\n");
//Delete Element of Stack
top=top-1;
while(top >= 0)
{
printf("\nElement Deleted from stack a[%d] = %d ",top,a[top]);
top=top-1;
}
printf("\nStack Empty");
getch();
}
Saturday, May 29, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment