I am not able to sort the string according to output.
Here is my code:
#include<bits/stdc++.h>
#include
using namespace std;
void generateBrackets(int n,char out,int i,int open,int close, vector &v){
//bc
if(i==2n){
out[i] = ‘\0’;
// cout<<out<<endl;
v.push_back(out);
}
//rc
if(open<n){
out[i] = ‘(’;
generateBrackets(n,out,i+1,open+1,close,v);
}
if(close<open){
out[i] = ‘)’;
generateBrackets(n,out,i+1,open,close+1,v);
}
}
int main() {
int n;
cin>>n;
char out[100];
vector v;
generateBrackets(n,out,0,0,0,v);
sort(v.begin(), v.end());
for (auto x : v)
cout << x << endl;
return 0;
}