{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full Document Right Arrow Icon
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
Background image of page 2
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 * /
Background image of page 3

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

View Full Document Right Arrow Icon
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); } }
Background image of page 4
Binary Search Trees
Background image of page 5

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

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}