search

Home  >  Q&A  >  body text

Is the queue last in first out or first in first out?

Is the queue last-in-first-out or first-in-first-out? The teacher said last in first out, but the actual result seems to be first in first out?

In addition, what is the difference between last in first out and first in last out?

王先生王先生1862 days ago13966

reply all(3)I'll reply

  • 十亿亿

    十亿亿2019-10-10 08:38:18

    You may have mistaken the stack and the queue. The stack is last in, first out. The queue is first in, first out.

    reply
    0
  • 王先生

    Please read my description carefully and try it yourself several times. Don't jump to conclusions so quickly. At first I thought the teacher had made a mistake. After careful consideration later, I found that it was correct. It just depends on how you understand it. The queue mentioned on the Internet, the so-called "first in, first out", refers to the elements at the front of the array that come out of the queue first. There is no

    王先生 · 2019-10-10 08:50:21
  • 王先生

    王先生2019-10-09 18:02:14

    Regarding the stack and queue modes, I personally think that the following explanation is reasonable:
    Stack operation (first in, last out mode: refers to the newly pushed data on the stack. When it is popped out of the stack, it is in the order in which it was originally pushed into the stack. In order, the data is pushed into the stack first and then popped out. In fact, it is popped out from the last data in the order after being pushed into the stack) ##%2

    reply
    0
  • Cancelreply