首页 > 其他 > 详细

自己实现数据结构---Queue

时间:2018-06-23 01:13:35      阅读:242      评论:0      收藏:0      [点我收藏+]

一.代码部分

1.定义接口:

public interface Queue<E> {

    void enqueue(E e);
    E dequeue();
    E getFront();
    int getSize();
    boolean isEmpty();

}

2.基于数组的实现

public class ArrayQueue<E> implements Queue<E> {

    private ArrayList<E> arrayList;
    public ArrayQueue(int capacity){
        arrayList = new ArrayList<>(capacity);
    }
    public ArrayQueue(){
        arrayList = new ArrayList<>();
    }

    @Override
    public void enqueue(E e) {
        arrayList.addLast(e);
    }

    @Override
    public E dequeue() {
        return arrayList.removeFirst();
    }

    @Override
    public E getFront() {
        return arrayList.get(0);
    }

    @Override
    public int getSize() {
        return arrayList.getSize();
    }

    @Override
    public boolean isEmpty() {
        return arrayList.isEmpty();
    }


}

 

自己实现数据结构---Queue

原文:https://www.cnblogs.com/inspred/p/queue.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!