I have a
typedef struct node
{
node* br;
node* son;
};
Given a string char* str which consits of sequence of (,)
I need to build a tree,for this string ,for example :
for string (()())() the following tree will be built:
br br
node ----- node ---- NULL
|son |son
| NULL
| br br br
node --- node --- node --- NULL
|son |son
NULL NULL
Your tree is a little hard to read. I’m assuming that each parenthesis is a node and all nested parenthesis are child nodes.
Here’s a simple algorithm:
This should give you a good looking tree. Ofc you have to check if the string is valid, and compensate/correct when needed.