public static <T> void inorder_traversal(BinaryTree<T> r) {
        // Empty tree.
        if (r == null) {
            return;
        }

        BinaryTree<T> prev = null, curr = r, next;
        while(curr != null) {
            if(prev == null || prev.getLeft() == curr || prev.getRight() == curr) {
                if(curr.getLeft() != null) {
                    next = curr.getLeft();
                } else {
                    System.out.println(curr.getData());
                    next = (curr.getRight() != null ? curr.getRight() : curr.getParent());
                }
            } else if(curr.getLeft() == prev) {
                System.out.println(curr.getData());
                next = (curr.getRight() != null ? curr.getRight() : curr.getParent());
            } else {
                next = curr.getParent();
            }

            prev = curr;
            curr = next;
        }
    }