Stack and Queue
- From: "raghu" <raghujindia@xxxxxxxxx>
- Date: 25 Oct 2006 10:07:00 -0700
// 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[i]); // here i'm filling (pushing) the elements
for(i=4;i>=0;i--)
printf("%d",a[i]); // here i'm poping out the elements
// now for queue
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(i=0;i<5;i++)
printf("%d",a[i]);
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
.
- Follow-Ups:
- Re: Stack and Queue
- From: Malcolm
- Re: Stack and Queue
- From: michael . kirby
- Re: Stack and Queue
- From: Richard Heathfield
- Re: Stack and Queue
- Prev by Date: how to fabricate a good computer
- Next by Date: Re: how to fabricate a good computer
- Previous by thread: how to fabricate a good computer
- Next by thread: Re: Stack and Queue
- Index(es):
Relevant Pages
|