package
Version:
v0.0.0-...-d229d73
Opens a new window with list of versions in this module.
Published: Dec 2, 2024
License: MIT
Opens a new window with license information.
Imports: 1
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
优先队列(Priority Queue)
优先队列中的每个元素都有各自的优先级,优先级最高的元素最先得到服务;优先级相同的元素按照其在优先队列中的顺序得到服务。优先队列往往用堆来实现。
操作
优先队列至少需要支持下述操作:
- 插入带优先级的元素(insert_with_priority);
- 取出具有最高优先级的元素(pull_highest_priority_element);
- 查看最高优先级的元素(peek):O(1) 时间复杂度。
其它可选的操作:
- 检查优先级高的一批元素;
- 清空优先队列;
- 批插入一批元素;
- 合并多个优先队列;
- 调整一个元素的优先级。
Documentation
¶
type Element struct {
Value interface{}
Priority int
}
func NewElement(value interface{}, priority int) (e *Element)
func PQConstructor() (pq *PQ)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.