我需要为我的算法II课程“创建一个由二叉搜索树(BST)实现的优先队列”。然而,我不确定如何使用二叉搜索树作为优先队列。有人能澄清一下这个任务要求我做什么吗?
以下是PriorityQueue必须实现的方法:
add – adds a new item to the queue
peek – returns the head of the queue
remove – removes the head of the queue and returns it
search – returns the position of an element in the queue, or -1 if it is not found.
size – returns the total number of elements in the queue
inorder – returns an in-order, comma-separated string of every element in the queue
preorder – returns an pre-order, comma-separated string of every element in the queue
height – returns the height of the underlying BST
非常感谢您提前的任何建议!!