Viii. the Java implementation of the queue

Source: Internet
Author: User

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

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.