Queue of "Data structure" (Java language description)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.