课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

What is a queue?

What is a queue?

- [Instructor] The queue is another data structure that can be particularly useful in algorithms where you need to process data in order. Like an array or list, a queue represents a series of objects, but the way we access, add and remove items is slightly different. A queue contains the elements in the order they were added. It's designed to have elements inserted at the end of the queue and elements removed from the beginning of the queue. You cannot remove items from the middle or end. You must remove from the front. Similarly, you cannot add items to the middle or front. You must add to the back. For this reason, we say queues follow a FIFO, or first in, first out policy. The first item in the queue must be the first item out of the queue. Now when we talk about adding and removing items, we refer to it as enqueueing and dequeueing. When we add an item, we enqueue it to the back of the queue. When we remove an item, we dequeue it from the front of the queue. We cannot add an…

内容