首页 > 编程语言 > 详细

队列(存储结构双端链表)--Java实现

时间:2017-10-17 14:29:12      阅读:233      评论:0      收藏:0      [点我收藏+]
 1 /*用链表实现的队列--使用的是双端链表
 2  *注意:空指针错误肯定是引用没有指向对象
 3  * */
 4 public class MyLinkedQueue {
 5     private MyFirstAndLastLinkedList list;
 6     private int items;
 7 
 8     public MyLinkedQueue() {
 9         list = new MyFirstAndLastLinkedList();
10         items = 0;
11     }
12     
13     public boolean isEmpty(){
14         return list.isEmpty();
15     }
16     
17     public void insert(int key){
18         list.insertLast(key);
19         items++;
20     }
21     
22     public Link remove(){
23         items--;
24         return list.deleteFirst();
25     }
26     
27     public void displayQueue(){
28         System.out.println("queue--front-- to--rear");
29         list.displayLinkedList();
30     }
31     
32     public int size(){
33         return items;
34     }
35 
36     public static void main(String[] args) {
37         MyLinkedQueue queue = new MyLinkedQueue();
38         for(int i = 0; i < 10; i++){
39             queue.insert(i);//尾巴插入
40         }
41         queue.displayQueue();
42         queue.remove();//移除头
43         queue.displayQueue();
44     }
45 }

 

队列(存储结构双端链表)--Java实现

原文:http://www.cnblogs.com/sun1993/p/7680550.html

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