ch5-2-tree-traversal-method

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

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

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.

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

View Full Document
Binary Tree Traversal Methods Preorder Inorder Postorder Level order
Preorder Traversal void preOrder(treePointer ptr) { if (ptr != NULL ) { visit(t); preOrder(ptr->leftChild); preOrder(ptr->rightChild); } }

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

View Full Document
Preorder Example (Visit = print) a b c a b c
Preorder Example (Visit = print) a b c d e f g h i j a b d g h e i c f j

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

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

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

View Full Document
Inorder Example (Visit = print) a b c b a c
Inorder Example (Visit = print) a b c d e f g h i j g d h b e i a f j c

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

View Full Document
Inorder By Projection (Squishing) a b c d e f g h i j g d h b e i a f j c
+ a b - c d + e f * / Gives infix form of expression (sans parentheses)! e

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/13/2011 for the course DATA STRUC 101 taught by Professor Hansanyong during the Spring '11 term at 한동대학교.

### 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
Ask a homework question - tutors are online