In this article, I briefly introduced the basic data structure and operation of the queue, and the C language code describes the performance of the queue.
The api--queue is provided by default in the JDK for us.
A queue is an interface that provides some basic methods for handling queues and their operations, and if we want to create our own queues, we need to create a class to implement the queue interface.
In the Java language, we have also provided some implementation classes for the queue interfaces that are ready-made, as follows:
* ** * * * * * * @see Java.util.concurrent.PriorityBlockingQueue
As you can see from the source comments above, there is a class in the implementation class of the queue that we usually use to encode: LinkedList . In other words, we can simply create a queue with the following code:
New Linkedlist<integer> ();
For a queue, the most important method is two, namely: into the queue and out of the queue. The queue interface also defines these two methods for us: Incoming queue offer () and Out Queue poll () , and of course, the implementation classes such as LinkedList. In LinkedList, the offer () method creates a new node and adds it to the end of the queue; The poll () method sets the header of the queue to the next node of the current queue header. The specific source code is as follows:
Public Boolean Offer (e) { return Add (e);} Public E Poll () { final node<e> f = First ; return NULL NULL : Unlinkfirst (f);}
Queue of "Data structure" (Java language description)