public void connect(TreeLinkNode root) {
        if(root == null) return;

        TreeLinkNode node = root.next;
        while(node != null && node.left == null && node.right == null){
            node = node.next;
        }

        TreeLinkNode next = node == null ? null : node.left != null ? node.left : node.right;

        if(root.left != null){
            root.left.next = root.right != null ? root.right : next;
        }

        if(root.right != null){
            root.right.next = next;
        }

        connect(root.right);
        connect(root.left);
    }