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