mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
Implemented AVLTree Example
1.ExampleNewAVLTree 2.ExampleNewAVLTreeFrom Implemented RedBlackTree Example 1.ExampleNewRedBlackTree 2.ExampleNewRedBlackTreeFrom
This commit is contained in:
parent
16a05f1450
commit
b0eb76359e
@ -14,11 +14,38 @@ import (
|
||||
)
|
||||
|
||||
func ExampleNewAVLTree() {
|
||||
avlTree := gtree.NewAVLTree(gutil.ComparatorString)
|
||||
for i := 0; i < 6; i++ {
|
||||
avlTree.Set("key"+gconv.String(i), "val"+gconv.String(i))
|
||||
}
|
||||
|
||||
fmt.Println(avlTree)
|
||||
|
||||
// Output:
|
||||
// │ ┌── key5
|
||||
// │ ┌── key4
|
||||
// └── key3
|
||||
// │ ┌── key2
|
||||
// └── key1
|
||||
// └── key0
|
||||
}
|
||||
|
||||
func ExampleNewAVLTreeFrom() {
|
||||
avlTree := gtree.NewAVLTree(gutil.ComparatorString)
|
||||
for i := 0; i < 6; i++ {
|
||||
avlTree.Set("key"+gconv.String(i), "val"+gconv.String(i))
|
||||
}
|
||||
|
||||
otherAvlTree := gtree.NewAVLTreeFrom(gutil.ComparatorString, avlTree.Map())
|
||||
fmt.Println(otherAvlTree)
|
||||
|
||||
// May Output:
|
||||
// │ ┌── key5
|
||||
// │ │ └── key4
|
||||
// └── key3
|
||||
// │ ┌── key2
|
||||
// └── key1
|
||||
// └── key0
|
||||
}
|
||||
|
||||
func ExampleNewBTree() {
|
||||
@ -46,9 +73,36 @@ func ExampleNewBTreeFrom() {
|
||||
}
|
||||
|
||||
func ExampleNewRedBlackTree() {
|
||||
rbTree := gtree.NewRedBlackTree(gutil.ComparatorString)
|
||||
for i := 0; i < 6; i++ {
|
||||
rbTree.Set("key"+gconv.String(i), "val"+gconv.String(i))
|
||||
}
|
||||
|
||||
fmt.Println(rbTree)
|
||||
|
||||
// Output:
|
||||
// │ ┌── key5
|
||||
// │ ┌── key4
|
||||
// │ ┌── key3
|
||||
// │ │ └── key2
|
||||
// └── key1
|
||||
// └── key0
|
||||
}
|
||||
|
||||
func ExampleNewRedBlackTreeFrom() {
|
||||
rbTree := gtree.NewRedBlackTree(gutil.ComparatorString)
|
||||
for i := 0; i < 6; i++ {
|
||||
rbTree.Set("key"+gconv.String(i), "val"+gconv.String(i))
|
||||
}
|
||||
|
||||
otherRBTree := gtree.NewRedBlackTreeFrom(gutil.ComparatorString, rbTree.Map())
|
||||
fmt.Println(otherRBTree)
|
||||
|
||||
// May Output:
|
||||
// │ ┌── key5
|
||||
// │ ┌── key4
|
||||
// │ ┌── key3
|
||||
// │ │ └── key2
|
||||
// └── key1
|
||||
// └── key0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user