github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/petar/GoLLRB/example/ex1.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "github.com/insionng/yougam/libraries/petar/GoLLRB/llrb" 6 ) 7 8 func lessInt(a, b interface{}) bool { return a.(int) < b.(int) } 9 10 func main() { 11 tree := llrb.New(lessInt) 12 tree.ReplaceOrInsert(1) 13 tree.ReplaceOrInsert(2) 14 tree.ReplaceOrInsert(3) 15 tree.ReplaceOrInsert(4) 16 tree.DeleteMin() 17 tree.Delete(4) 18 c := tree.IterAscend() 19 for { 20 u := <-c 21 if u == nil { 22 break 23 } 24 fmt.Printf("%d\n", int(u.(int))) 25 } 26 }