can anyone explain me this thing: I want implement priority queue in GO (interface implementation got from link, but for lowest)
My code:
pq := make(PriorityQueue, 0)
pq.Push(&Item{value: 0, priority: 0})
heap.Init(&pq)
fmt.Println(heap.Pop(&pq).(*Item))
item := &Item{value: 1, priority: 10}
pq.Push(item)
item = &Item{value: 2, priority: 20}
pq.Push(item)
item = &Item{value: 3, priority: 5}
pq.Push(item)
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
fmt.Println(heap.Pop(&pq).(*Item))
// Output:
&{0 0 -1}
&{1 10 -1}
&{3 5 -1}
&{2 20 -1}
Why it not outputs:
&{0 0 -1}
&{3 5 -1}
...