Valid queues for Java data structures

Source: Internet
Author: User
/** * @ Describes ordered pairs of columns * Inserting data from any location is ordered * @ Project name Java_datastruct * @ Package Name Com.java.stack * @ class name Queue * @author Chenlin * @date
    June 5, 2011 Afternoon 8:12:47 * * public class Sequequeue {private long[] arr;
        private int maxsize;//maximum space private int len;//valid length public sequequeue (int size) {this.maxsize = size;
        This.arr = new Long[maxsize];
    This.len = 0;
        /** * Insert Data * * @param value */public void Insert (Long value) {int i;
            for (i = 0; i < len; i++) {//Get I if (Value > Arr[i]) {break;
        }///move data, move the previous data back one for (int j = len; j > i; j--) {arr[j] = arr[j-1];
        } Arr[i] = value;
    Len + +;
     /** * Remove data, remove the last one at a time, length--array from 0 to len-1;
        */Public long Remove () {Long value = arr[len-1];
        Len--;
    return value; 
   /** * Determine if it is empty *  * @return/public Boolean isempty () {return (len = = 0);
    /** * Judge whether full * * @return/public boolean isfull () {return (len = = maxSize);
    /** * Gets the valid length of the queue * * @return/public int size () {return len;
        public static void Main (string[] args) {sequequeue queue = new Sequequeue (8);
        Queue.insert (22);
        Queue.insert (33);
        Queue.insert (44);
        Queue.insert (534);
        Queue.insert (21);

        Queue.insert (55);
        while (!queue.isempty ()) {System.out.println (Queue.remove ()); }


    }
}

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.