Created
May 24, 2018 01:46
-
-
Save reyou/a897b3fc4169fa7205d783574da607ee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.youtube.com/watch?v=gm8DUJJhmY4 | |
// Binary tree traversal: Preorder, Inorder, Postorder | |
1. Visit root | |
2. Visit left sub tree | |
3. Visit right sub tree | |
struct Node { | |
char data; | |
Node *left; | |
Node *right; | |
} | |
void Preorder(struct Node *root){ | |
if(root == NULL) return; | |
printf("%c ", root->data); | |
Preorder(root->left); | |
Preorder(root->right); | |
} | |
void Inorder(struct Node *root){ | |
if(root == NULL) return; | |
Preorder(root->left); | |
printf("%c ", root->data); | |
Preorder(root->right); | |
} | |
void Postorder(struct Node *root){ | |
if(root == NULL) return; | |
Preorder(root->left); | |
Preorder(root->right); | |
printf("%c ", root->data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment