/** * Note: The returned array must be malloced, assume caller calls free(). */ void bracket(int left,int right,int n,char arr[],char c,char **returns,int *returnSize) { if(left == 0 && right == 0) { arr[left+right] = c; } else{ arr[left+right-1] = c; } printf("%c",c); if(left < right || left > n || right > n) return; if(left == n && right == n) { returns[(*returnSize)] = (char *)calloc((2*n+1),sizeof(char)); // printf("%s",arr); strcpy(returns[(*returnSize)],arr); (*returnSize)++; return; } bracket(left+1,right,n,arr,'(',returns,returnSize); bracket(left,right+1,n,arr,')',returns,returnSize); return; } // void copy(char *dest,char *src) // { // int i,j=0; // for(i=0;i<strlen(src);i++) // { // dest[j]=src[i]; // } // printf("%s\n",dest); // } char ** generateParenthesis(int n, int* returnSize){ *returnSize = 0; printf("@"); char ** returns = (char **)malloc(sizeof(char *)*1500); printf("1"); char * arr = (char *)calloc((2*n+1),sizeof(char)); bracket(0,0,n,arr,'(',returns,returnSize); return returns; }