1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2020-2022 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 unsigned int CUR_IDX
= 0;
34 node
*new_node
= &(node_array
[CUR_IDX
++]);
35 new_node
->left
= NULL
;
36 new_node
->right
= NULL
;
38 new_node
->visited
= false;
44 tree_insert (node
*root
, int val
)
49 tree_insert (root
->left
, val
);
51 root
->left
= make_node(val
);
53 else if (val
> root
->id
)
56 tree_insert (root
->right
, val
);
58 root
->right
= make_node(val
);
65 std::vector
<node
*> todo
;
66 todo
.push_back (root
);
69 node
*curr
= todo
.back();
70 todo
.pop_back(); /* break-here */
72 std::cout
<< curr
->id
<< " ";
77 todo
.push_back (curr
->right
);
78 todo
.push_back (curr
);
80 todo
.push_back (curr
->left
);
86 main (int argc
, char **argv
)
88 node
*root
= make_node (35);
90 tree_insert (root
, 28);
91 tree_insert (root
, 20);
92 tree_insert (root
, 60);