File tree Expand file tree Collapse file tree 1 file changed +18
-15
lines changed
er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof Expand file tree Collapse file tree 1 file changed +18
-15
lines changed Original file line number Diff line number Diff line change @@ -37,28 +37,31 @@ func ReverseInOrderIterator(ctx context.Context, root *TreeNode) (gen chan int)
37
37
38
38
return
39
39
}
40
- WriteAll (ctx , gen , ReverseInOrderIterator (ctx , root .Right ))
41
- select {
42
- case <- ctx .Done ():
43
- return
44
- default :
45
- gen <- root .Val
46
- }
47
- WriteAll (ctx , gen , ReverseInOrderIterator (ctx , root .Left ))
40
+ YieldAll (ctx , gen , ReverseInOrderIterator (ctx , root .Right ))
41
+ YieldOne (
42
+ ctx , gen , root .Val )
43
+
44
+ YieldAll (ctx , gen , ReverseInOrderIterator (ctx , root .Left ))
48
45
49
46
}()
50
47
51
48
return
52
49
}
53
- func WriteAll (ctx context.Context , target chan int , source chan int ) {
50
+ func YieldAll (ctx context.Context , target chan int , source chan int ) {
54
51
55
52
for v := range source {
56
- select {
57
- case <- ctx .Done ():
58
- return
59
- default :
60
- target <- v
61
- }
53
+ YieldOne (
54
+ ctx , target , v )
62
55
63
56
}
64
57
}
58
+ func YieldOne (ctx context.Context , target chan int , source int ) {
59
+
60
+ select {
61
+ case <- ctx .Done ():
62
+ return
63
+ default :
64
+ target <- source
65
+ }
66
+
67
+ }
You can’t perform that action at this time.
0 commit comments