The basic data structure of queue data structures ---: FIFO
Baidu Encyclopedia:
A queue is a special linear form , is special in that it only allows deletion at the front end of the table (Front), while the rear end of insertion, the table (REAR), and the same stack,
A queue is a limited linear operating table. Referred to as the tail end of the end, delete operation will be referred to as head-of-insertion operation.
Code shows:
public class MyQueue { Private int [] ARR; // underlying queue implementation is an array Private int Front; // HOL Private int REAR; // the tail Private int size; // initialize queue capacity // initialization public MyQueue ( int size) { ARR = new new int [size]; Front = 0 ; REAR = -1 ; the this .size = size; } // enqueue public void insertQueue ( int n-) { IF (isFull ()) { System.out.println ( "queues are full!" ); } the else { ARR [ ++ REAR] = n-; } } // dequeue public int getQueue () { int n-; IF (isEmpty ()) { n- = 0 ; System.out.println ( "empty stack!" ); } the else { n- = ARR [Front]; Front++ ; } return n-; } // if the drug case is null public Boolean isEmpty () { return Front == (REAR +. 1 ); } // determines whether the team full public Boolean isFull () { return (REAR +. 1) == size; } public int getQueueLength () { return (REAR +. 1) - Front; } public static void main (String [] args) { MyQueue myQueue = new new MyQueue (10 ); int i=0; while(!myQueue.isFull()){ myQueue.insertQueue(++i); } System.out.println(myQueue.getQueueLength()); while(!myQueue.isEmpty()){ System.out.println(myQueue.getQueue()); } System.out.println(myQueue.getQueueLength()); } }