zoukankan      html  css  js  c++  java
  • 队列(存储结构双端链表)--Java实现

     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 }
  • 相关阅读:
    万丈高楼平地起
    @synthesis 使用的时候注意的地方
    arc4random()
    Whereami: CLLocationManager not calling delegate
    总结
    生病两日,真是难受
    Xcode 5 Error CertUIFramework.axbundle
    c++笔记 重要的声明
    class
    检查没有错误或警告
  • 原文地址:https://www.cnblogs.com/sun1993/p/7680550.html
Copyright © 2011-2022 走看看