public void connect(TreeLinkNode root) {
        while (root != null) {
            TreeLinkNode p = root;
            while (p != null) {
                if (p.left != null && p.right != null) {
                    p.left.next = p.right;
                    p.right.next = getNextLevelFirst(p.next);
                } else if (p.left != null || p.right != null) {
                    getNextLevelFirst(p).next = getNextLevelFirst(p.next);
                }
                p = p.next;
            }
            root = getNextLevelFirst(root);
        }
    }