首页 > 编程语言 > 详细

java循环队列实现代码

时间:2019-09-22 18:27:36      阅读:103      评论:0      收藏:0      [点我收藏+]

循环队列

java实现代码

 1 /**
 2  *   java循环队列实现代码
 3  *  5  */
 6 
 7  8 
 9 public class QueueArray {
10 
11     Object[] arr=new Object[10];;//队列最多存储arr.length-1个对象 
12     int front=0;//队首
13     int rear=0;//队尾
14     
15     /**
16      *  入队
17      */
18     public boolean enqueue(Object obj) {
19         if((rear+1)%arr.length==front) {
20             return false;
21         }
22         arr[rear]=obj;
23         rear=(rear+1)%arr.length;
24         return true;
25     
26     }
27     
28     //出队列
29     public Object dequeue() {
30         if(rear==front) {
31             return null;
32         }
33         Object obj=arr[front];
34         front=(front+1)%arr.length;
35         return obj;
36     }
37   }

 

java循环队列实现代码

原文:https://www.cnblogs.com/henabo/p/11568359.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!