| How can I construct this tree, |
|
|
00001000101 |
|
|
00001000101 |
| I received the same error when I debug @lastchance's solution. For the line , node *root = new node{ 0 }; I receive ; it is not possible to convert initializer list to a node . |
new node{ 0, 0, 0 }; |
|
| learner999 wrote: |
|---|
| The second question, maybe @lastchance can also answer it? For an additional condition for example if the value is negative then insert one node which holds 1 (the same idea when we insert one node which holds 0 when e<3),how can we do that? |
|
|
010001100101011 |
root 0
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
/ \
check 6 0 1
/ \ / \
/ \ / \
/ \ / \
/ \ / \
check 4 0 1 0 1
/ / / /
/ / / /
check 1 0 0 0 0
\ \ \ \
check -2 1 1 1 1
===========================================
0 10 0 0 11 0 0 10 1 0 11 |
| one more question to @seeplus and I would be very happy if you can answer. In your solution, the point I can not understand how it decides it will make two branches 0 and 1 or just 0. For example the first value in the array is 6 which corresponds 1 in terms of boolean , is not it How does it insert the other branch which holds 0? |
| learner999 wrote: |
|---|
| When I iplement your code , I receive the following error: main.cpp: In function ‘void insert(node*, bool, bool)’: main.cpp:20:48: error: no matching function for call to ‘node::node()’ 20 | if ( add0 ) n->left = new node{ 0, 0, 0 }; How can I fix it ? |
|
|