Skip to content

Commit 9c468f9

Browse files
authored
Update index.go
1 parent 6f08675 commit 9c468f9

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

binary-search-tree-iterator/index.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ func InOrderIterator(ctx context.Context, root *TreeNode) (gen chan int) {
4444

4545
return
4646
}
47+
48+
select {
49+
case <-ctx.Done():
50+
return
51+
default:
52+
{}
53+
}
54+
4755
YieldAll(ctx, gen, InOrderIterator(ctx, root.Left))
4856
YieldOne(
4957
ctx, gen, root.Val)

0 commit comments

Comments
 (0)