Generate Parentheses problem

It is giving wrong answer. I think my code is fine. Maybe the order of printing is different. Please help how to get the correct order.
Code Link: https://ide.codingblocks.com/s/135341

Rishav i would suggest you to maintain a function :
void balanced_parentheses(int pos,int n,int open,int close)
and then check if
if(close==n)
if(open>close)
if(open<n)
and based on these three conditions, apply recursive calls

Can I store all possible permutations in an string array and then sort it in lexicographical order?? Will it work?

You can try that approach since your answer is correct … only order is not coming.