Thursday, December 13, 2012

PUSH Operation of A Stack, CSE-206 [12.12.12]

PUSH Operation of A Stack

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int stack[5],i,top,maxstk,data,choise;
top=-1;maxstk=4;
printf("What do you want to do? PUSH/nothing (1/2):");
scanf("%d",&choise);
while (choise==1)
{
if(top==maxstk)
{
printf("overflow");
exit(1);
}
else
{
printf("\n Enter data:");
scanf("%d",&data);
top=top+1;
stack[top]=data;
printf("\n Now the stack is \n");
for(i=0;i<=top;i++)
printf("%d ",stack[i]);
}
printf("\nWhat do you want to do? PUSH/nothing (1/2):");
scanf("%d",& choise);
}
}

Post Comment