A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/dd/d1e/generate__parentheses_8cpp_source.html below:

TheAlgorithms/C++: backtracking/generate_parentheses.cpp Source File

Go to the documentation of this file. 28

std::vector<std::string>

res

;

30 void makeStrings

(std::string str,

int

n,

int

closed,

int

open);

33

std::vector<std::string>

generate

(

int

n);

46 int

closed,

int

open) {

50 if

((str.length() == 2 * n) &&

55 if

(str.length() == 2 * n) {

72

std::string str =

"("

;

84

std::vector<std::string> patterns;

88

patterns = {{

"()"

}};

92

patterns = {{

"()()()"

}, {

"()(())"

}, {

"(())()"

}, {

"(()())"

}, {

"((()))"

}};

97

patterns = {{

"()()()()"

}, {

"()()(())"

}, {

"()(())()"

}, {

"()(()())"

},

98

{

"()((()))"

}, {

"(())()()"

}, {

"(())(())"

}, {

"(()())()"

},

99

{

"(()()())"

}, {

"(()(()))"

}, {

"((()))()"

}, {

"((())())"

},

100

{

"((()()))"

}, {

"(((())))"

}};

101

assert(p.

generate

(n) == patterns);

103

std::cout <<

"All tests passed\n"

;

generate_parentheses class

std::vector< std::string > res

Contains all possible valid patterns.

void makeStrings(std::string str, int n, int closed, int open)

function that adds parenthesis to the string.

std::vector< std::string > generate(int n)

wrapper interface

static void test()

Self-test implementations.

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4