Exercise: Equivalent Binary Trees
Step 1. Implement the Walk function — do an in-order traversal of the tree and send each value to ch.
Step 2. Test Walk. The function tree.New(k) builds a randomly structured (but always sorted) binary tree with values k, 2k, 3k, …, 10k. Kick off a walk and read from the channel:
go Walk(tree.New(1), ch)
Read 10 values from ch — you should get 1, 2, 3, …, 10 in order.
Step 3. Implement Same using Walk. Walk both trees and compare the sequences value by value. If they match throughout, return true.
Step 4. Test Same.
Same(tree.New(1), tree.New(1))should returntrueSame(tree.New(1), tree.New(2))should returnfalse
The Tree type documentation is here.