private void insert_helper(Node ptr, Node prev, int direction, int num) {
        if (ptr == null) {
            switch (direction) {
                case 0:
                    prev.left = new Node(num);
                    break;
                case 1:
                    prev.mid = new Node(num);
                    break;
                case 2:
                    prev.right = new Node(num);
                    break;
                default:
                    break;
            }
            return;
        }
        int val = ptr.val;
        if (val == num) {
            insert_helper(ptr.mid, ptr, 1, num);
        } else if (val < num) {
            insert_helper(ptr.right, ptr, 2, num);
        } else {
            insert_helper(ptr.left, ptr, 0, num);
        }
    }