【发布时间】:2017-11-04 15:20:47
【问题描述】:
我正在通过这个接口实现一个基于数组的priorityQueue:
public interface IPriorityQueue {
/**
* Adds an element to the queue.
*
* @param element the element to be queued
* @throws QueueFullException if there is no room in the queue for the new element
*/
void enqueue(Comparable element) throws QueueFullException;
/**
* Removes the largest element.
*
* @return the element removed
* @throws QueueEmptyException if the queue is empty
*/
Comparable dequeue() throws QueueEmptyException;
/**
* Returns the number of elements in the queue.
* @return the number of elements in the queue
*/
int size();
/**
* Checks whether the queue is empty.
* @return true if the queue is empty
*/
boolean isEmpty();
/**
* Removes all elements from the queue.
*/
void clear();}
如果我要使用基于数组的通用对象队列,我想知道在实现这些方法时的根本区别是什么。
【问题讨论】:
-
我不明白你的问题。您还没有发布任何实现。只有一个接口(使用原始类型,这是一个非常糟糕的主意)。所以,你问什么和什么之间的区别?为什么你首先要实现 PriorityQueue? Java 有一个标准的。
-
这是一个通过谷歌搜索很容易找到的问题:队列是“先进先出”的,而优先级队列由提供诸如堆或树之类的顺序的数据结构支持。投票结束这个问题过于广泛。
-
我没有正确理解这个问题。你能解释一下吗?
标签: java interface queue priority-queue comparable