6.顺序循环队列
来源:互联网 发布:淘宝柯巴 编辑:程序博客网 时间:2024/05/16 07:25
package sequenceQueue;//队列接口public interface Queue { //入队 public void append(Object obj) throws Exception; //出队 public Object delete() throws Exception; //获得队头元素 public Object getFront() throws Exception; //判断对列是否为空 public boolean isEmpty();}
package sequenceQueue;//循环顺序队列public class CircleSequenceQueue implements Queue { static final int defaultSize = 10; //默认队列的长度 int front; //队头 int rear; //队尾 int count; //统计元素个数的计数器 int maxSize; //队的最大长度 Object[] queue; //队列 public CircleSequenceQueue() { init(defaultSize); } public CircleSequenceQueue(int size) { init(size); } public void init(int size) { maxSize = size; front = rear = 0; count = 0; queue = new Object[size]; } @Override public void append(Object obj) throws Exception { // TODO Auto-generated method stub if (count > 0 && front == rear) { throw new Exception("队列已满!"); } queue[rear] = obj; rear = (rear + 1) % maxSize; count++; } @Override public Object delete() throws Exception { // TODO Auto-generated method stub if (isEmpty()) { throw new Exception("队列为空!"); } Object obj = queue[front]; front = (front + 1) % maxSize; count--; return obj; } @Override public Object getFront() throws Exception { // TODO Auto-generated method stub if (!isEmpty()) { return queue[front]; } else { return null; } } @Override public boolean isEmpty() { // TODO Auto-generated method stub return count == 0; }}
阅读全文
0 0
- 6.顺序循环队列
- SeqQueue--顺序循环队列
- 顺序循环队列
- 顺序循环队列
- 循环顺序队列
- C++循环顺序队列
- 循环队列-顺序表
- 循环顺序队列
- _DataStructure_C_Impl:顺序循环队列
- C++循环顺序队列
- 顺序循环队列
- 顺序循环队列
- 循环顺序队列
- 顺序循环队列
- 循环队列顺序储存
- 循环队列---顺序存储
- 循环队列(顺序队列)
- 循环队列(顺序队列)
- 双十一临近,怎样让买家流畅地秒杀? ——腾讯WeTest独家开放电商产品压测服务
- 2乘n铺骨牌
- 职责链模式(C++)
- 回调函数
- 问题 H: 部分A+B (15)
- 6.顺序循环队列
- 重拾Java EE(3)——JavaScript
- 环信聊天时长按图片保存到本地
- Critical Mass
- 用openjtag检验新的U-Boot是否支持SDRAM
- AngularJs添加 删除 排序 查找 最后汇总的代码
- 11 运行库
- 人工智障学习笔记——机器学习(1)特征工程
- 二维坐标排序