ch5-2-tree-traversal-method

ch5-2-tree-traversal-method - Binary Tree Traversal Methods...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Binary Tree Traversal Methods In a traversal of a binary tree, each element of the binary tree is visited exactly once. During the visit of an element, all action (make a clone, display, evaluate the operator, etc.) with respect to this element is taken.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Binary Tree Traversal Methods Preorder Inorder Postorder Level order
Background image of page 2
Preorder Traversal void preOrder(treePointer ptr) { if (ptr != NULL ) { visit(t); preOrder(ptr->leftChild); preOrder(ptr->rightChild); } }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Preorder Example (Visit = print) a b c a b c
Background image of page 4
Preorder Example (Visit = print) a b c d e f g h i j a b d g h e i c f j
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Preorder Of Expression Tree + a b - c d + e f * / Gives prefix form of expression! / * + a b - c d + e f
Background image of page 6
Inorder Traversal void inOrder(treePointer ptr) { if (ptr != NULL ) { inOrder(ptr->leftChild); visit(ptr); inOrder(ptr->rightChild); } }
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Inorder Example (Visit = print) a b c b a c
Background image of page 8
Inorder Example (Visit = print) a b c d e f g h i j g d h b e i a f j c
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Inorder By Projection (Squishing) a b c d e f g h i j g d h b e i a f j c
Background image of page 10
+ a b - c d + e f * / Gives infix form of expression (sans parentheses)! e
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 27

ch5-2-tree-traversal-method - Binary Tree Traversal Methods...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online