Principle:
The team is in the tail and the team heads out.
Run
There is nothing wrong with popping data from one queue at a time, but there is an error when the data is popped back into the array when the data is inserted again because the font and end are not reset and the next loop queue will solve the problem.
Source:
public class Myqueue {
Private int[] array; Underlying array
private int elements; Number of valid data
private int font; Team Head
private int end; End of Team
Public Myqueue () {
TODO auto-generated Constructor stub
Array = new INT[5];
elements = 0;
Font = 0;
end = 0;
}
Public myqueue (int Maxsize)//Heavy Construction
{
Array = new Int[maxsize];
elements = 0;
Font = 0;
end = 0;
}
public void Insert (int value)//Insert Data
{
array[end++] =value;
elements++;
}
public int Remove ()//delete data
{
elements--;
return array[font++];
}
public void Peek ()//view Team Header data
{
System.out.println (Array[font]);
}
public boolean IsEmpty ()//Determines whether it is empty
{
return elements ==0;
}
public boolean isfull ()//To determine if full
{
return elements = = Array.Length;
}
}
Viii. the Java implementation of the queue