Skip to content

Instantly share code, notes, and snippets.

@reyou
Created May 24, 2018 01:46
Show Gist options
  • Save reyou/a897b3fc4169fa7205d783574da607ee to your computer and use it in GitHub Desktop.
Save reyou/a897b3fc4169fa7205d783574da607ee to your computer and use it in GitHub Desktop.
// 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