package
0.0.0-20250221070010-8f85b7a13d98
Repository: https://github.com/axengine/utils.git
Documentation: pkg.go.dev

# README

非线程安全的优先队列(golang标准库中的heap是小根堆)

package main

import (
	"fmt"
	"github.com/gansidui/priority_queue"
)

type Node struct {
	priority int
	value    int
}

func (this *Node) Less(other interface{}) bool {
	return this.priority < other.(*Node).priority
}

func main() {
	q := priority_queue.New()

	q.Push(&Node{priority: 8, value: 1})
	q.Push(&Node{priority: 7, value: 2})
	q.Push(&Node{priority: 9, value: 3})

	x := q.Top().(*Node)
	fmt.Println(x.priority, x.value)

	for q.Len() > 0 {
		x = q.Pop().(*Node)
		fmt.Println(x.priority, x.value)
	}

	// output:
	// 7 2

	// 7 2
	// 8 1
	// 9 3
}

##LICENSE

MIT

# Functions

No description provided by the author

# Structs

Define priority queue struct.

# Interfaces

No description provided by the author