You're not closing the channel. You'll notice that it's actually printing correctly, then freaking out.
In a range
over a channel, like this:
for obj := range result {
//...
}
The loop will only exit if you call close(result)
. In this case it's a bit tricky because of the recursive nature. Ultimately I'd recommend wrapping the call to InOrder
like so:
func InOrder(t *Tree, chTree chan obj) {
inOrder(t, chTree)
close(chTree)
}
func inOrder(t *Tree, chTree chan Obj) {
if t != nil {
inOrder(t.Left, chTree)
chTree <- t.Item
inOrder(t.Rigth, chTree)
}
}