mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 10:58:39 +01:00
code kata 230811
This commit is contained in:
@@ -92,6 +92,21 @@ func postOrder2(n *node) {
|
||||
}
|
||||
}
|
||||
|
||||
func levelOrder(n *node) {
|
||||
q := MakeQueue()
|
||||
q.EnQueue(n)
|
||||
for !q.IsEmpty() {
|
||||
p := q.DeQueue().(*node)
|
||||
visit(p)
|
||||
if p.left != nil {
|
||||
q.EnQueue(p.left)
|
||||
}
|
||||
if p.right != nil {
|
||||
q.EnQueue(p.right)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreOrder(t *testing.T) {
|
||||
preOrder(makeBinary())
|
||||
}
|
||||
@@ -116,6 +131,10 @@ func TestPostOrder2(t *testing.T) {
|
||||
postOrder2(makeBinary())
|
||||
}
|
||||
|
||||
func TestLevelOrder(t *testing.T) {
|
||||
levelOrder(makeBinary())
|
||||
}
|
||||
|
||||
func visit(n *node) {
|
||||
if n == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user