先决条件 – 编程中的 FIFO(先进先出)方法
FIFO是先入先出的缩写。它是一种处理数据结构的方法,首先处理第一个元素,最后处理最新的元素。
现实生活中的例子:
LIFO是 Last in, first out的缩写,与 fist in, last out (FILO) 相同。它是一种处理数据结构的方法,首先处理最后一个元素,最后处理第一个元素。
现实生活中的例子:
以下是 FIFO 与 LIFO 的比较:
FIFO | LIFO |
---|---|
It stands for First-In-First-Out approach in programming. | It stands for Last-In-First-Out approach in programming. |
In this, the new element is inserted below the existing element, So that the oldest element can be at the top and taken out first. | In this, the new element is inserted above the existing element, So that the newest element can be at the top and taken out first. |
Therefore, the First element to be entered in this approach, gets out First. | Therefore, the First element to be entered in this approach, gets out Last. |
In computing, FIFO approach is used as an operating system algorithm, which gives every process CPU time in the order they arrive. | In computing, LIFO approach is used as a queuing theory that refers to the way items are stored in types of data structures. |
The data structure that implements FIFO is Queue. | The data structure that implements LIFO is Stack. |