Skip to content

Commit

Permalink
tour: let reader know Walk should send in order
Browse files Browse the repository at this point in the history
In "Exercise: Equivalent Binary Trees" neither the slide text nor the
code state Walk() should send the values in order. Doing so in order
makes using the output much more useful in Same(), but might not be easy
to see for readers that have not had a data structures class. In order
traversal is implied by reference with the binary tree being "always
sorted" and the output defined as "should be the numbers 1, 2, 3, ...,
10."

Update the slide text to say what Walk() does. Change Walk() comments in
code/solution to match.

Fixes golang/tour#158
  • Loading branch information
crisman committed Feb 28, 2023
1 parent 034fa41 commit e1db6b5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion _content/tour/concurrency.article
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Continue description on [[javascript:click('.next-page')][next page]].

* Exercise: Equivalent Binary Trees

*1.* Implement the `Walk` function.
*1.* Implement the `Walk` function to send all `t` values to `ch` in order.

*2.* Test the `Walk` function.

Expand Down
4 changes: 2 additions & 2 deletions _content/tour/concurrency/exercise-equivalent-binary-trees.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ package main

import "golang.org/x/tour/tree"

// Walk walks the tree t sending all values
// from the tree to the channel ch.
// Walk walks the sorted tree t sending all values
// in order from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int)

// Same determines whether the trees
Expand Down
4 changes: 2 additions & 2 deletions _content/tour/solutions/binarytrees.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ func walkImpl(t *tree.Tree, ch chan int) {
walkImpl(t.Right, ch)
}

// Walk walks the tree t sending all values
// from the tree to the channel ch.
// Walk walks the sorted tree t sending all values
// in order from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
walkImpl(t, ch)
// Need to close the channel here
Expand Down
4 changes: 2 additions & 2 deletions _content/tour/solutions/binarytrees_quit.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func walkImpl(t *tree.Tree, ch, quit chan int) {
walkImpl(t.Right, ch, quit)
}

// Walk walks the tree t sending all values
// from the tree to the channel ch.
// Walk walks the sorted tree t sending all values
// in order from the tree to the channel ch.
func Walk(t *tree.Tree, ch, quit chan int) {
walkImpl(t, ch, quit)
close(ch)
Expand Down

0 comments on commit e1db6b5

Please sign in to comment.