其他分享
首页 > 其他分享> > [简单] 622. 设计循环队列

[简单] 622. 设计循环队列

作者:互联网

https://leetcode-cn.com/problems/design-circular-queue/

 

请原谅我直接,这一题。。。我这么傻心里都嘀咕,怎么出得那么傻~没有灵魂得题目。

 

class MyCircularQueue {


    List<Integer> queue = new ArrayList<>();
    Integer capacity = 100000;

    public MyCircularQueue(int k) {
        capacity = k;
    }

    public boolean enQueue(int value) {
        if (queue.size() < capacity) {
            queue.add(value);
            return true;
        }
        return false;
    }

    public boolean deQueue() {
        if(queue.size() == 0) {
            return false;
        }
        queue.remove(0);
        return true;
    }

    public int Front() {
        if(queue.size() == 0) {
            return -1;
        }
        return queue.get(0);
    }

    public int Rear() {
        if(queue.size() == 0) {
            return -1;
        }
        return queue.get(queue.size()  -1);
    }

    public boolean isEmpty() {
        return (queue.size() == 0);
    }

    public boolean isFull() {
        return (queue.size() == capacity);
    }
}

/**
 * Your MyCircularQueue object will be instantiated and called as such:
 * MyCircularQueue obj = new MyCircularQueue(k);
 * boolean param_1 = obj.enQueue(value);
 * boolean param_2 = obj.deQueue();
 * int param_3 = obj.Front();
 * int param_4 = obj.Rear();
 * boolean param_5 = obj.isEmpty();
 * boolean param_6 = obj.isFull();
 */
View Code

 

标签:622,return,队列,queue,循环,boolean,obj,public,size
来源: https://www.cnblogs.com/chenxiaomai/p/16098266.html