mirror of
https://github.com/duke-git/lancet.git
synced 2026-03-01 00:35:28 +08:00
docs: add doc for PriorityQueue
This commit is contained in:
@@ -30,7 +30,7 @@ import (
|
|||||||
- [Dequeue](#ArrayQueue_Dequeue)
|
- [Dequeue](#ArrayQueue_Dequeue)
|
||||||
- [Front](#ArrayQueue_Front)
|
- [Front](#ArrayQueue_Front)
|
||||||
- [Back](#ArrayQueue_Back)
|
- [Back](#ArrayQueue_Back)
|
||||||
- [Front](#ArrayQueue_Size)
|
- [Size](#ArrayQueue_Size)
|
||||||
- [IsEmpty](#ArrayQueue_IsEmpty)
|
- [IsEmpty](#ArrayQueue_IsEmpty)
|
||||||
- [IsFull](#ArrayQueue_IsFull)
|
- [IsFull](#ArrayQueue_IsFull)
|
||||||
- [Clear](#ArrayQueue_Clear)
|
- [Clear](#ArrayQueue_Clear)
|
||||||
@@ -45,7 +45,7 @@ import (
|
|||||||
- [Dequeue](#LinkedQueue_Dequeue)
|
- [Dequeue](#LinkedQueue_Dequeue)
|
||||||
- [Front](#LinkedQueue_Front)
|
- [Front](#LinkedQueue_Front)
|
||||||
- [Back](#LinkedQueue_Back)
|
- [Back](#LinkedQueue_Back)
|
||||||
- [Front](#LinkedQueue_Size)
|
- [Size](#LinkedQueue_Size)
|
||||||
- [IsEmpty](#LinkedQueue_IsEmpty)
|
- [IsEmpty](#LinkedQueue_IsEmpty)
|
||||||
- [Clear](#LinkedQueue_Clear)
|
- [Clear](#LinkedQueue_Clear)
|
||||||
- [Contain](#LinkedQueue_Contain)
|
- [Contain](#LinkedQueue_Contain)
|
||||||
@@ -58,7 +58,7 @@ import (
|
|||||||
- [Dequeue](#CircularQueue_Dequeue)
|
- [Dequeue](#CircularQueue_Dequeue)
|
||||||
- [Front](#CircularQueue_Front)
|
- [Front](#CircularQueue_Front)
|
||||||
- [Back](#CircularQueue_Back)
|
- [Back](#CircularQueue_Back)
|
||||||
- [Front](#CircularQueue_Size)
|
- [Size](#CircularQueue_Size)
|
||||||
- [IsEmpty](#CircularQueue_IsEmpty)
|
- [IsEmpty](#CircularQueue_IsEmpty)
|
||||||
- [IsFull](#CircularQueue_IsFull)
|
- [IsFull](#CircularQueue_IsFull)
|
||||||
- [Clear](#CircularQueue_Clear)
|
- [Clear](#CircularQueue_Clear)
|
||||||
@@ -73,6 +73,7 @@ import (
|
|||||||
- [Dequeue](#PriorityQueue_Dequeue)
|
- [Dequeue](#PriorityQueue_Dequeue)
|
||||||
- [IsEmpty](#PriorityQueue_IsEmpty)
|
- [IsEmpty](#PriorityQueue_IsEmpty)
|
||||||
- [IsFull](#PriorityQueue_IsFull)
|
- [IsFull](#PriorityQueue_IsFull)
|
||||||
|
- [Size](#PriorityQueue_Size)
|
||||||
|
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
@@ -1336,3 +1337,51 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="PriorityQueue_Size">Size</span>
|
||||||
|
<p>Get nubmers of elements in queue</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func (q *PriorityQueue[T]) Size() int
|
||||||
|
```
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
queue "github.com/duke-git/lancet/v2/datastructure/queue"
|
||||||
|
)
|
||||||
|
|
||||||
|
type intComparator struct{}
|
||||||
|
|
||||||
|
func (c *intComparator) Compare(v1, v2 any) int {
|
||||||
|
val1, _ := v1.(int)
|
||||||
|
val2, _ := v2.(int)
|
||||||
|
|
||||||
|
if val1 < val2 {
|
||||||
|
return -1
|
||||||
|
} else if val1 > val2 {
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
comparator := &intComparator{}
|
||||||
|
q := queue.NewPriorityQueue[int](10, comparator)
|
||||||
|
fmt.Println(q.IsFull()) // false
|
||||||
|
|
||||||
|
for i := 1; i < 5; i++ {
|
||||||
|
q.Enqueue(i)
|
||||||
|
}
|
||||||
|
fmt.Println(q.Size()) // 4
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user