⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.java

📁 Java程序设计技巧与开发实例附书源代码。
💻 JAVA
字号:

public class Queue
{
   private Node head;
   private Node tail;
   public Queue()
   {
      head = tail = null;
   }

   public void enqueue(Object obj)
   {
      Node node = new Node(obj);
      if (head == null)
      {
         head = node;
      }
      else
      {
         tail.next = node;
      }
      tail = node;
   }

   public Object dequeue() throws QueueException
   {
      if (head == null)
      {
         throw new QueueException("removing from empty queue");
      }
      else
      {
         Object data = head.data;
         head = head.next;
         if (head == null)
         {
            tail = null;
         }
         return data;
      }
   }

   public Object peek() throws QueueException
   {
      if (head == null)
      {
         throw new QueueException("peeking into empty queue");
      }
      else
      {
         return head.data;
      }
   }

   public boolean isEmpty()
   {
      return (head == null);
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -