Skip to content

Module 2 (BST Traversal)

Dyandra Paramitha edited this page Apr 1, 2021 · 1 revision

Traversal Binary Search Tree

  • Inorder Traversal

    void __inorder(BSTNode *root) {
        if (root) {
            __inorder(root->left);
            printf("%d ", root->key);
            __inorder(root->right);
        }
    }
  • Postorder Traversal

    void __postorder(BSTNode *root) {
        if (root) {
            __postorder(root->left);
            __postorder(root->right);
            printf("%d ", root->key);
        }
    }
  • Preorder Traversal

    void __preorder(BSTNode *root) {
        if (root) {
            printf("%d ", root->key);
            __preorder(root->left);
            __preorder(root->right);
        }
    }

For example on a Binary Search Tree :

The results printed out will be like this :

  • Inorder : 1 2 3 4 5 6 7
  • Postorder : 1 3 4 2 7 6 5
  • Preorder : 5 2 1 4 3 6 7

Navigasi

Home

Modul 0

Modul 1

Modul 2

Modul 3

  • Self-Balancing Binary Search Tree IND | ENG
  • AVL Tree IND | ENG

Modul 4

Modul 5

Clone this wiki locally