diff --git a/Recursion/Print_balanced_paranthesis_by_recursion.cpp b/Recursion/Print_balanced_paranthesis_by_recursion.cpp new file mode 100644 index 0000000..b805f52 --- /dev/null +++ b/Recursion/Print_balanced_paranthesis_by_recursion.cpp @@ -0,0 +1,36 @@ +//proposed by dark_coder +#include +using namespace std; +void generateParenthesis(int n, int open, int close, string s, vector &ans) +{ + + if (open == n && close == n) + { + ans.push_back(s); + return; + } + + if (open < n) + { + generateParenthesis(n, open + 1, close, s + "{", ans); + } + + if (close < open) + { + generateParenthesis(n, open, close + 1, s + "}", ans); + } +} +int main() +{ + int n; + cout<<"Enter number of paranthesis you want to print combination of (eg '1' if '()')"<>n; + vector ans; + generateParenthesis(n, 0, 0, "", ans); + cout<