Which is better to determine stack and queue and why? XD
- First In First Out
- First In Last Out
- Last In First Out
- Last In Last Out
Which is better to determine stack and queue and why? XD
- First In First Out
- First In Last Out
- Last In First Out
- Last In Last Out
Um, are you taking some C quiz online?
What do you mean by "better"? We're talking definitions here. A stack is one way and a queue is another.
A queue is a First In First Out (FIFO). Because the first element stored in the queue will first go out :P
Like you have:
1-2-3-4-5
you insert another one:
1-2-3-4-5-6
If you take one you ll start first from the beginning (from 1, 2 etc)
A stack is Last in First Out. Because if you inserted 6 (push) and you wanted to get an element from the stack (pull), you would get 6, then 5 etc etc
That's not something you could find by googling though!!
Last edited by C_ntua; 07-03-2008 at 02:50 PM.
There is no better; the stack works on LIFO, and the queue works on FIFO.
I mean, why you choose to say stack is LIFO not FILO, and queue is FIFO not LILO? XD
Well, just...because. It is the same thing anyhow.
People usually see it at the scope of extracting data. If you want 10 elements from a stack you ask yourself "what will I get"? The answer is FIRST you ll get the values stored LAST.
You don't care that the last element will be taken last. You care about the data that you will get now. So FIFO is more "nice" than LILO.
EDIT: Don't ask why we say LIFO and not FOLI :P
So it's depend on what we care or not...
Queues and Stacks are the concept which is there, and you know what they. Its very important to know how they work. Once you get the grip of that. You could answer any question regarding that. After that its upto to you call its as FILO or LIFO.
Its like my name is Harish Shivaraj in here where I stay. But when I get back to home country my name is S.Harish. or Harish S. There just different. As a person i am still the same
ssharish