MengBridgeCourse 中文版

第 10 章 队列与泛型

| 关于   英文版   «  10.1. 泛型的更多知识   ::   目录   ::   10.3. 单元 10 实验 1 占位符  »

10.2. 队列

10.2.1. 目标

完成本模块后,学生将能够:

  • 命名基本 Java 数据结构的功能与用途

  • 阐述 Java 中队列的关键特征

  • 构建并填充 Java 中的队列

10.2.1.1. 建议阅读

第 10 章: 队列、双端队列和优先队列 与 第 11 章: 队列、双端队列和优先队列实现 来自 Data Structures and Abstractions with Java 由 Frank M. Carrano 和 Timothy Henry

10.2.2. 交互式:队列入门 [8:50]

Follow Along, Practice, and Explore

下载并运行及探索(见下文)视频中的 java 文件(在 eclipse 中)。您可以下载此示例的独立 *.java 文件。

QueueInterface.java
package queue;

/**
   An interface for the ADT queue.
   @author Frank M. Carrano
   @author Timothy M. Henry
   @version 4.0
*/
public interface QueueInterface
{
  /** Adds a new entry to the back of this queue.
      @param newEntry  An object to be added. */
  public void enqueue(T newEntry);

  /** Removes and returns the entry at the front of this queue.
      @return  The object at the front of the queue.
      @throws  EmptyQueueException if the queue is empty before the operation. */
  public T dequeue();

  /**  Retrieves the entry at the front of this queue.
      @return  The object at the front of the queue.
      @throws  EmptyQueueException if the queue is empty. */
  public T getFront();

  /** Detects whether this queue is empty.
      @return  True if the queue is empty, or false otherwise. */
  public boolean isEmpty();

  /** Removes all entries from this queue. */
  public void clear();
} // end QueueInterface
Video Slides 10.2.2.1-QueueIntro.pdf

10.2.3. 检查点 1

10.2.4. 编程练习:队列 1

10.2.5. 交互式:链接队列介绍与入队 [11:29]

Follow Along, Practice and Explore

Video Slides 10.2.4.1-LinkedQueuesEnqueue.pdf

10.2.6. 检查点 2

10.2.7. 交互式:链接队列的移除与更多功能(出队和其他方法)[8:41]

Follow Along, Practice and Explore

Video Slides 10.2.5.1-LinkedQueueRemove.pdf

10.2.8. 检查点 3

10.2.9. 交互式:双端队列入门 [13:51]

Follow Along, Practice and Explore

下载并运行及探索(见下文)视频中的 java 文件(在 eclipse 中)。您可以下载此示例的独立 *.java 文件。

DequeInterface.java
Video Slides 10.2.6.1-DequeIntro.pdf
package deque;

/**
 * An interface for the ADT deque.
 *
 * @author Frank M. Carrano
 * @author Timothy M. Henry
 * @version 4.0
 * @param  generic type for the deque
 */
public interface DequeInterface
{
    /**
     * Adds a new entry to the front of this dequeue.
     *
     * @param newEntry
     *            An object to be added.
     */
    public void addToFront(T newEntry);

    /**
     * Adds a new entry to the back of this dequeue.
     *
     * @param newEntry
     *            An object to be added.
     */
    public void addToBack(T newEntry);

    /**
     * Removes and returns the front entry of this dequeue.
     *
     * @return The object at the front of the dequeue.
     * @throws EmptyDequeException
     *             if the dequeue is empty before the operation.
     */
    public T removeFront();

    /**
     * Removes and returns the back entry of this dequeue.
     *
     * @return The object at the back of the dequeue.
     * @throws EmptyDequeException
     *             if the dequeue is empty before the operation.
     */
    public T removeBack();

    /**
     * Retrieves the front entry of this dequeue.
     *
     * @return The object at the front of the dequeue.
     * @throws EmptyDequeException
     *             if the dequeue is empty before the operation.
     */
    public T getFront();

    /**
     * Retrieves the back entry of this dequeue.
     *
     * @return The object at the back of the dequeue.
     * @throws EmptyDequeException
     *             if the dequeue is empty before the operation.
     */
    public T getBack();

    /**
     * Detects whether this dequeue is empty.
     *
     * @return True if the queue is empty, or false otherwise.
     */
    public boolean isEmpty();

    /**
     * Removes all entries from this dequeue.
     */
    public void clear();
} // end DequeInterface

10.2.10. 检查点

10.2.11. 交互式:双端队列移除与总结 [9:02]

Follow Along, Practice and Explore

Video Slides 10.2.7.1-DequeRemoveAndWrapUp.pdf

10.2.12. 检查点 5

10.2.13. 交互式:数组队列:数组实现的队列 [11:08]

Follow Along and Engage

下载与视频对应的幻灯片。观看视频时,在幻灯片上做笔记,并亲自练习绘制图表!

Video Slides 10.2.8.1-ArrayQueueIntro.pdf

10.2.14. 检查点 6

10.2.15. 交互式:ArrayQueue:一个未使用的存储位置 [7:11]

Follow Along and Engage

下载与视频对应的幻灯片。观看视频时,在幻灯片上做笔记,并亲自练习绘制图表!

Video Slides 10.2.9.1-ArrayQueueRemove.pdf

10.2.16. 检查点 7

10.2.17. 交互式:ArrayQueue:确保容量 [14:06]

Follow Along and Engage

下载与视频对应的幻灯片。观看视频时,在幻灯片上做笔记,并亲自练习绘制图表!

Video Slides 10.2.10.2-ArrayQueueEnsureCapacity.pdf

10.2.18. 检查点 8

10.2.19. 交互式:数组队列总结 [6:59]

Follow Along and Engage

下载与视频对应的幻灯片。观看视频时,在幻灯片上做笔记,并亲自练习绘制图表!

Video Slides 10.2.11.1-ArrayQueueWrapUp.pdf

Empty Queue Exception

package queue;

/**
* A class of runtime exceptions thrown by methods to indicate that a queue is
* empty.
*
* @author Frank M. Carrano
* @author Timothy M. Henry
* @version 4.0
*/

public class EmptyQueueException extends RuntimeException {
    /**
     * serial Version UID
     */
    private static final long serialVersionUID = 960025440830878197L;

    public EmptyQueueException() {
        this(null);
    } // end default constructor

    public EmptyQueueException(String message) {
        super(message);
    } // end constructor
} // end EmptyQueueException

10.2.20. 编程练习:队列 2

   «  10.1. 泛型的更多知识   ::   目录   ::   10.3. 单元 10 实验 1 占位符  »

关闭窗口