{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lab8 - COP 3502 Lab Notes Tree Traversals and BSTs This lab...

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

COP 3502 – Lab Notes Tree Traversals and BSTs This lab is designed to give you some practice with binary tree traversal algorithms and binary search trees. The last question is from a previous foundation exam. Binary Tree Traversals Preorder a b c Postorder b c a Inorder b a c a b c

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

View Full Document
Preorder a b d g h e i c f j Postorder g h d i e b j f c a Inorder g d h b e i a f j c a b c d e f g h i j
Do a Preorder, Postorder and Inorder traversal of this tree. Preorder traversal: / * + a b - c d + e f Postorder traversal: a b + c d - * e f + / Inorder traversal: a + b * c d / e + f + a b - c d + e f * /

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

View Full Document
Binary Tree Traversal Algorithms Preorder (Depth-First Search) void preorder(struct treeNode * p) { if (p !=NULL) { printf(“%d\n”, p->data); preorder(p->left_child); preorder(p->right_child); } } Inorder void inorder(struct treeNode *p) { if (p !=NULL) { inorder(p->left_child); printf(“%d\n”, p->data); inorder(p->right_child); } } Postorder void postorder(struct treeNode *p) { if (p !=NULL) { postorder(p->left_child); postorder(p->right_child); printf(“%d\n”, p->data); } }
Binary Search Trees

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.

{[ snackBarMessage ]}