R
raghu
// Program to implement both stack and queue on an array
int main(void)
{
int a[5],i;
for(i=0;i<5;i++)
scanf("%d",&a); // here i'm filling (pushing) the elements
for(i=4;i>=0;i--)
printf("%d",a); // here i'm poping out the elements
// now for queue
for(i=0;i<5;i++)
scanf("%d",&a);
for(i=0;i<5;i++)
printf("%d",a);
return;
}
My logic for stack is which ever item is stored in the last should be
taken out first and so on...so I have filled the array and printing
them from the last....Am I correct?????
As for the Queue FIFO logic.So the item which is stored first is
printed first and so on...
Is this program correct? Please help..
Thanks a lot in advance.
Regards,
Raghu
int main(void)
{
int a[5],i;
for(i=0;i<5;i++)
scanf("%d",&a); // here i'm filling (pushing) the elements
for(i=4;i>=0;i--)
printf("%d",a); // here i'm poping out the elements
// now for queue
for(i=0;i<5;i++)
scanf("%d",&a);
for(i=0;i<5;i++)
printf("%d",a);
return;
}
My logic for stack is which ever item is stored in the last should be
taken out first and so on...so I have filled the array and printing
them from the last....Am I correct?????
As for the Queue FIFO logic.So the item which is stored first is
printed first and so on...
Is this program correct? Please help..
Thanks a lot in advance.
Regards,
Raghu