学习队列结构
2016-08-05 22:12
148 查看
package com.loong.datastructure; /** * 学习队列结构 * * @author Loong * */ public class Queue { private Object[] item = new Object[100]; private int front;// 对头 private int rear;// 队尾 private int count; public Queue() { } /** * 初始化队列 */ public void initQueue() { front = rear = count = 0; } /** * 判断队列是否为空 * * @return */ public boolean isQueueEmpty() { return count == 0; } /** * 判断队列是否已满 * * @return */ public boolean isQueueFull() { return count == item.length; } /** * 进队列 * * @param o */ public void enQueue(Object o) { if (isQueueFull()) { throw new RuntimeException("队列已满"); } if (rear >= this.item.length) { if (count < this.item.length) { rear = 0; } } item[rear++] = o; count++; } /** * 获取队首元素 * * @return */ public Object getFront() { if (isQueueEmpty()) { throw new RuntimeException("队列为空"); } return this.item[front]; } /** * 出队列 * * @return */ public Object deQueue() { if (isQueueEmpty()) { throw new RuntimeException("队列为空"); } Object o = null; if (front > this.item.length - 1) { front = 0; } o = this.item[front]; this.item[front++] = null; count--; return o; } }
相关文章推荐
- 数据结构(Java 队列模拟)本代码重在学习数据结构思路,代码完整性欠缺,请见谅
- 网络设备发送队列相关数据结构及其创建函数 (linux网络子系统学习 第十节 )
- 4Java学习笔记之数据结构——队列
- 【嵌入式学习历程10】数据结构之队列
- 数据结构与算法学习之队列及队列的相关操作
- 数据结构 学习笔记(三):线性结构:堆栈,队列,表达式求值,多项式加法运算
- 【数据结构与算法学习笔记】PART3 线性结构(除向量外,数组、栈、队列、链表)
- 学习笔记--数据结构(之二)队列
- 【算法学习笔记】06.数据结构基础 队列与堆栈初步
- 【算法学习笔记】06.数据结构基础 队列与堆栈初步
- 慕课网学习笔记之数据结构队列(C++)
- 【学习笔记----数据结构05-栈与队列】
- 数据结构与算法学习笔记——队列
- 学习笔记:数据结构(二)栈与队列
- (三)Android数据结构学习之队列
- 信管16数据结构:第三章栈和队列的课前翻转学习任务
- 数据结构再学习--队列
- 学习java数据结构基础知识之队列
- Java之数据结构基础、线性表、栈和队列、数组和字符串,树—学习笔记
- 结构之美学习二《栈和队列》