Good day.
I want to write an RRT, but first I wanted to write a regular tree, only so that the pointers to the right and left descendant were stored in a vector.
Writing:
#include <iostream> //#include <GL\freeglut.h> #include <ctime> #include <cmath> #include <vector> #include <iterator> using namespace std ; struct Node{ int value ; vector <Node*> Children(2) ; }; void Push(int info, Node *&tree){ if(tree == NULL){ tree = new Node ; tree -> value = info ; tree -> Children[0] = NULL ; tree -> Children[1] = NULL ; } if(info > tree -> value){ Push(info, tree -> Children[1]) ; } if(info < tree -> value){ Push(info, tree -> Children[0]) ; } } void Show(Node *&tree){ if(tree != NULL){ Show(tree -> Children[0]) ; cout << tree -> value << " " ; Show(tree -> Children[1]) ; } } int main(){ Node *tree = NULL ; int x ; for (int i = 0; i < 7 ; i++){ cout << "Put : " ; cin >> x ; Push(x, tree) ; cout << endl ; } Show(tree) ; return 0 ; } Errors:
expected unqualified-id before numeric constant in the structure.
invalid types ' unresolved overloaded function type int ' for array subscript in each function.
Help me to understand. I am new to vectors, so errors can be trivial, thanks in advance for your understanding.
Update
As I understood: vector <Node*> Children(2) - it was not worth it. It was necessary vector <Node*> Children ; .
But now how to address descendants?