Java简单队列的实现
2012-03-19 02:06
495 查看
/** * */ package com.handy.ds; /** * @author handy * */ public class SimpleQueue { // 队列最大长度 private int maxSize; // 队列数组 private int[] queue; // 队头 private int front; // 队尾 private int rear; // 队列元素大小 private int size; public SimpleQueue(int maxSize) { this.maxSize = maxSize; front = 0; rear = -1; size = 0; queue = new int[maxSize]; } /** * @return the maxSize */ public int getMaxSize() { return maxSize; } /** * @param maxSize * the maxSize to set */ public void setMaxSize(int maxSize) { this.maxSize = maxSize; } /** * @return the queue */ public int[] getQueue() { return queue; } /** * @param queue * the queue to set */ public void setQueue(int[] queue) { this.queue = queue; } /** * @return the front */ public int getFront() { return front; } /** * @param front * the front to set */ public void setFront(int front) { this.front = front; } /** * @return the rear */ public int getRear() { return rear; } /** * @param rear * the rear to set */ public void setRear(int rear) { this.rear = rear; } /** * @return the size */ public int getSize() { return size; } /** * @param size * the size to set */ public void setSize(int size) { this.size = size; } public boolean isFull() { if (size == maxSize) return true; else return false; } public boolean isEmpty() { if (size == 0) return true; else return false; } public void enQueue(int number) { if (!isFull()) { if (rear == maxSize - 1) // 队列循环 rear = -1; queue[++rear] = number; size++; } else System.out.println("队列满了!"); } public int deQueue() { if (!isEmpty()) { int temp = queue[front++]; // 队列循环 if (front == maxSize) front = 0; size--; return temp; } else { System.out.println("空队列!"); return -1; } } // 返回队头,不改变队列大小 public int queueFront() { if (!isEmpty()) { return queue[front]; } else { System.out.println("空队列!"); return -1; } } }
相关文章推荐
- JAVA实现最简单的双向链表、队列与栈(内部使用链表形式存储)
- 利用JAVA线程安全队列简单实现读者写者问题。
- java并发-使用内置条件队列实现简单的有界缓存
- 使用java实现阿里云消息队列简单封装
- Java语言实现简单FTP软件 FTP上传下载队列窗口实现(7)
- 数据结构之动态队列的java简单实现
- Java语言实现简单FTP软件------>上传下载队列窗口的实现(七)
- 【数据结构+Java】Java实现简单队列、循环队列操作
- java 数据结构 队列的简单实现
- Java:实现简单的阻塞队列
- Java基础课程学习总结,使用LinkedList简单模拟队列数据结构和堆栈数据结构的实现
- Java语言实现简单FTP软件------>上传下载队列窗口的实现(七)
- java 环形队列简单实现
- 浅谈使用java实现阿里云消息队列简单封装
- 队列--基于简单循环数组实现(Java)
- Java简单实现固定长度队列(FIFO)
- Java简单实现固定长度队列
- 消息队列Java的简单实现
- java线程实现简单 消息队列 1对1模式
- 数据结构之静态队列的java简单实现