in this question i have successfully generated the parenthesis , but we have to sort them in a order opposite to the printed order so what i did was try the store the printed value in another array and then print that array in reverse order , in the main function, but i’m unsuccessful in doing so . can you tell me how to go about it
Balance parethesis
In this question you have to print parenthesis:
Create,
output character array : char ans[]
p: position
o: count of open brackets
c: count of close
n: input
genParenthesis: function that takes four arguments: p,n,o,c
Now check:
- if(c == n): Print the ans array
- else if(o > c) {
ans[p] = ‘)’;
genParenthesis(p+1, n, o, c+1);
}
Similarly do when o<c
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.