*
**Run this to generate all balanced parantheses:
//sudosuhan
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MAX_SIZE 200
void _printParenthesis(int pos, int n1, int open1, int close1, int n2, int open2, int close2, int n3, int open3, int close3);
void printParenthesis(int n1 , int n2 , int n3 )
{
if(n1 > 0 || n2 > 0 || n3 > 0)
_printParenthesis(0, n1, 0, 0, n2, 0, 0, n3, 0, 0);
return;
}
void _printParenthesis(int pos, int n1, int open1, int close1, int n2, int open2, int close2, int n3, int open3, int close3)
{
static char str[MAX_SIZE];
if(close1 == n1 && close2 == n2 && close3 == n3 )
{
printf("%s \n", str);
return;
}
else
{
bool run1 = open1 > close1;
bool run2 = open2 > close2;
bool run3 = open3 > close3;
if(run3)
{
str[pos] = ')';
_printParenthesis(pos+1, n1, open1, close1, n2, open2, close2, n3, open3, close3+1);
if(open3 < n3)
{
str[pos] = '(';
_printParenthesis(pos+1, n1, open1, close1, n2, open2, close2, n3, open3+1, close3);
}
}
else if(run2 && !run3)
{
str[pos] = '}';
_printParenthesis(pos+1, n1, open1, close1, n2, open2, close2+1, n3, open3, close3);
if(open3 < n3)
{
str[pos] = '(';
_printParenthesis(pos+1, n1, open1, close1, n2, open2, close2, n3, open3+1, close3);
}
if(open2 < n2)
{
str[pos] = '{';
_printParenthesis(pos+1, n1, open1, close1, n2, open2+1, close2, n3, open3, close3);
}
}
else if(run1 && !run2 && !run3)
{
str[pos] = ']';
_printParenthesis(pos+1, n1, open1, close1+1, n2, open2, close2, n3, open3, close3);
if(open3 < n3)
{
str[pos] = '(';
_printParenthesis(pos+1, n1, open1, close1, n2, open2, close2, n3, open3+1, close3);
}
if(open2 < n2)
{
str[pos] = '{';
_printParenthesis(pos+1, n1, open1, close1, n2, open2+1, close2, n3, open3, close3);
}
if(open1 < n1)
{
str[pos] = '[';
_printParenthesis(pos+1, n1, open1+1, close1, n2, open2, close2, n3, open3, close3);
}
}
else if(!run1 && !run2 && !run3)
{
if(open3 < n3)
{
str[pos] = '(';
_printParenthesis(pos+1, n1, open1, close1, n2, open2, close2, n3, open3+1, close3);
}
if(open2 < n2)
{
str[pos] = '{';
_printParenthesis(pos+1, n1, open1, close1, n2, open2+1, close2, n3, open3, close3);
}
if(open1 < n1)
{
str[pos] = '[';
_printParenthesis(pos+1, n1, open1+1, close1, n2, open2, close2, n3, open3, close3);
}
}
}
}
/* driver program to test above functions */
int main()
{
int n1, n2, n3;
n1 = 6;
n2 = 1;
n3 = 1;
printParenthesis(n1, n2, n3);
return 0;
}**
*