Java实现泛型队列

2020-12-13 16:37

阅读:465

标签:queue   max   ace   java实现   swa   warnings   turn   string   out   

class node{
    int x;
    int y;
}

public class Test {
    
     public static void main(String[] args) {
        MyQueue q=new MyQueue();
         q.push("xxx");
         q.push("xxx");
         q.push("xxx");
         q.push("你");
         q.push("真");
         q.push("666!");
         q.print();
        System.out.println(q.GetMaxSize());
    }
}


class MyQueue{
    public int HIndex=0;
    public int size=0;
    public int MaxSize=0;
    public T space[];
    @SuppressWarnings("unchecked")
    public boolean push(T t) {
        if(MaxSizesize){
            MaxSize=MaxSize+((MaxSize>>1)>1?(MaxSize>>1):1);
            T temp[]=(T[])new Object[MaxSize];
            for(int i=0;ii) {
                temp[i]=space[i];
            }
            space=temp;
        }
        space[size++]=t;
        return true;
        
    }
    public boolean pop() {
        if(!isEmpty()) {
            HIndex++;
            size--;
        }
        return true;
        
    }
    public boolean isEmpty() {
        
        if(size==0) {
            return true;
        }
        return false;
    }
    public boolean print() {
        for(int i=HIndex;ii) {
            System.out.println(space[i]);
        }
        return true;
    }
    public int GetMaxSize() {
        return MaxSize;
    }
}

 

Java实现泛型队列

标签:queue   max   ace   java实现   swa   warnings   turn   string   out   

原文地址:https://www.cnblogs.com/z2529827226/p/11621034.html


评论


亲,登录后才可以留言!