With data structures what are the implementations of using LIFO and FIFO? |
[Edit] |
Answer
Think about what each concept means.
A LIFO stack is like a supermarket queue - people are served in the order in which they arrive in line. You'd use a LIFO stack for a process that requires sequential access to data in arrival order, such as transaction processing.
On the other hand, a FIFO stack is like an elevator - the people who board last are nearest the front, so they're the first off in "processing" order. You might use a FIFO stack for something like expression parsing. For example, if you're trying to match up parens, you need to use the "nearest match" rule. That means if you have already stacked two "("s you'd want to pair the most recently-scanned one with the first closing ")" encountered and evaluate the enclosed expression. That means the ")" would pair off with the "(" at the top of your paren stack rather than the bottom; i.e. FIFO.
First answer by JayKay. Last edit by JayKay. Contributor trust: 875 [recommend contributor]. Question popularity: 21 [recommend question]
|
Research your answer: |



