package Queue;/*@author: Roderland@create: 2020年08月11日---18:17*/public class MyArrayQueue<E> {private static final int DEFAULT_CAPACITY = 10;private E[] array;private int head;private int limit;public MyArrayQueue() {array = (E[]) new Object[DEFAULT_CAPACITY];}public MyArrayQueue(int capacity) {array = (E[]) new Object[capacity];}public void push(E o) {if (isOutOfLength()) expansion();array[limit++] = o;}public E peek() {if (isEmpty()) throw new IndexOutOfBoundsException("队列空");return array[head];}public E pop() {if (isEmpty()) throw new IndexOutOfBoundsException("队列空");return array[head++];}public boolean isOutOfLength() {return limit >= array.length;}public boolean isEmpty() {return head >= limit;}public void expansion() {E[] newArray = (E[]) new Object[(limit - head) * 2];for (int i = head, j = 0; i < limit; i++, j++) {newArray[j] = array[i];}array = newArray;limit = limit - head;head = 0;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。