Skip to content

Commit 7ef73d9

Browse files
committed
Update index.go
1 parent 16ed8e3 commit 7ef73d9

File tree

1 file changed

+18
-15
lines changed
  • er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof

1 file changed

+18
-15
lines changed

er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof/index.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,31 @@ func ReverseInOrderIterator(ctx context.Context, root *TreeNode) (gen chan int)
3737

3838
return
3939
}
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))
4845

4946
}()
5047

5148
return
5249
}
53-
func WriteAll(ctx context.Context, target chan int, source chan int) {
50+
func YieldAll(ctx context.Context, target chan int, source chan int) {
5451

5552
for v := range source {
56-
select {
57-
case <-ctx.Done():
58-
return
59-
default:
60-
target <- v
61-
}
53+
YieldOne(
54+
ctx, target, v)
6255

6356
}
6457
}
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+
}

0 commit comments

Comments
 (0)