priorityqueue

package
v0.0.0-...-e6cce5a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOutOfCapacity = errors.New("队列已满")
	ErrEmptyQueue    = errors.New("队列为空")
)

Functions

This section is empty.

Types

type PriorityQueue

type PriorityQueue[T any] struct {
	// contains filtered or unexported fields
}

func NewPriorityQueue

func NewPriorityQueue[T any](capacity int, less func(a, b T) bool) *PriorityQueue[T]

func (*PriorityQueue[T]) Dequeue

func (pq *PriorityQueue[T]) Dequeue() (T, error)

Dequeue 移除并返回最小元素

func (*PriorityQueue[T]) Enqueue

func (pq *PriorityQueue[T]) Enqueue(item T) error

Enqueue 添加一个元素

func (*PriorityQueue[T]) Len

func (pq *PriorityQueue[T]) Len() int

Len 返回队列的长度

func (*PriorityQueue[T]) Less

func (pq *PriorityQueue[T]) Less(i, j int) bool

Less 比较两个元素的大小

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() interface{}

Pop 移除并返回最小元素

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(x interface{})

Push 添加一个元素

func (*PriorityQueue[T]) Swap

func (pq *PriorityQueue[T]) Swap(i, j int)

Swap 交换两个元素

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL