Learn the basics of Java data structures in the queue

Source: Internet
Author: User

Queues are FIFO.
Implementing the queue code using the Java language:
/* Queue */public class Queue {private int maxSize;          Maximum Queue private long[] Quearray;      Queue array private int front;            Team head private int rear;             Team tail private int nitems;           Number of current queue elements//constructor public queue (int s) {super (); this.maxsize = S;this.quearray = new Long[maxsize];this.front = 0;this.rear = -1;this.nitems = 0;} Insert element public void Insert (long j) {if (rear = = (MaxSize-1)) {rear =-1;} Quearray[++rear] =j;nitems++;} Delete element public long remove () {Long temp =quearray[front++];if (front ==maxsize) {front = 0;} Nitems--;return temp;} Queue Header public long Peekfront () {return quearray[front];} Whether the queue is empty public boolean isEmpty () {return (Nitems ==0);} Whether the queue is full of public boolean isfull () {return (nitems==maxsize);} Queue Length public int size () {return nitems;}}
<pre name= "code" class= "Java" >public class Queueapp {public static void main (string[] arg) {Queue thequeue =new Que UE (5); Thequeue.insert (Thequeue.insert); Thequeue.insert (+); Thequeue.insert (+); Thequeue.remove (); Thequeue.remove (); Thequeue.remove (); Thequeue.insert (Thequeue.insert); Thequeue.insert (70); Thequeue.insert, while (!thequeue.isempty ()) {Long n = thequeue.remove (); System.out.print (n); System.out.print ("  ");} System.out.print ("");}}



Learn the basics of Java data structures in the queue

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.