标签:复杂 static pen nts style ack 图片 enqueue cap
数组队列的实现:
队列的实现:
package com.lt.datastructure.Queue; public class ArrayQueue<E> implements Queue<E> { private Array1<E> array; public ArrayQueue(int capacity){ array = new Array1<>(capacity); } public ArrayQueue(){ array = new Array1<>(); } @Override public int getSize() { return array.getSize(); } @Override public boolean isEmpty() { return array.isEmpty(); } @Override public void enqueue(E e) { array.addLast(e); } @Override public E dequeue() { return array.removeFirst(); } @Override //查看队首 public E getFront(E e) { return array.getFirst(); } @Override public String toString() { StringBuilder res = new StringBuilder(); res.append("Queue:"); res.append("front:["); for(int i=0; i<array.getSize();i++){ res.append(array.get(i)); if(i!=array.getSize()-1){ res.append(","); } } res.append("] tail"); return res.toString(); } public static void main(String[] args) { ArrayQueue<Integer> queue = new ArrayQueue<>(); for(int i =0; i<10; i++){ queue.enqueue(i); System.out.println(queue); if(i%3==2){ queue.dequeue(); System.out.println(queue); } } } }
测试:
复杂度;
标签:复杂 static pen nts style ack 图片 enqueue cap
原文地址:https://www.cnblogs.com/ltfxy/p/9972074.html