init
This commit is contained in:
42
dtask/pkg/rbtree/example/example_int/example_int.go
Normal file
42
dtask/pkg/rbtree/example/example_int/example_int.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2015, Hu Keping. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/oofpgDLD/dtask/pkg/rbtree"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rbt := rbtree.New()
|
||||
|
||||
m := 0
|
||||
n := 10
|
||||
|
||||
for m < n {
|
||||
rbt.Insert(rbtree.Int(m))
|
||||
m++
|
||||
}
|
||||
|
||||
m = 0
|
||||
for m < n {
|
||||
if m%2 == 0 {
|
||||
rbt.Delete(rbtree.Int(m))
|
||||
}
|
||||
m++
|
||||
}
|
||||
|
||||
rbt.Ascend(rbt.Min(), print)
|
||||
}
|
||||
|
||||
func print(item rbtree.Item) bool {
|
||||
i, ok := item.(rbtree.Int)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
fmt.Println(i)
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user