Перевести код Java в переполнение стека

у меня есть код дерева решений Java для передачи в C ++.
Я плохо помню логические внутренние указатели, когда пытаюсь построить дерево.
Java-код:

public class Node {
Node parent;
Node children[];
List<Instance> instances;
....
};

Node(Node parent, List<Instance> instances) {
this.parent = parent;
children = new Node[Instance.FTSVALUERANGE];
this.instances = instances;
....
}

Для генерации дерева:

public class ID3 {
Node root;
...

public static Node generate(List<Instance> instances) {
Node root = new Node(null, instances);
expand(root, 0);
return root;
}
static void expand(Node node, int depth) {
...
ArrayList<ArrayList<Instance>> ts = new ArrayList<ArrayList<Instance>>();
...
/* Grow the tree recursively */
for (int i = 0; i < Instance.FTSVALUERANGE; i++) {
if (ts.get(i).size() > 0) {
node.children[i] = new Node(node, ts.get(i));
expand(node.children[i], depth + 1);
}
}}}

И вот моя реализация C ++; Узел:

class Node
{
public:
Node();
Node(Node* parent, std::vector<Instance>& instances);
Node* parent;
Node** children;
std::vector<Instance> instances;

....
};

Node::Node()
{
parent=NULL;
children=NULL;
}
Node::Node(Node* parent, std::vector<Instance>& instances) {
this->parent = parent;
this->children = new Node*[Instance::FTSVALUERANGE];
this->instances = instances;
...
};

Для генерации дерева:

class ID3{
Node* root;
static void expand(Node* node, int depth);
static Node* generate(vector<Instance> instances);
...
};
Node* ID3::generate(vector<Instance> instances) {
Node* root = new Node(NULL, instances);
expand(root, 0);// when use ID3.chi_square_100// there is no prunning,
return root;
}
void ID3::expand(Node* node,int depth){
...
for (int i = 0; i < Instance::FTSVALUERANGE; i++) {
if (ts[i].size() > 0) {
node->children[i] = new Node(node, ts[i]);
expand(node->children[i], depth + 1);
}
}}}

Когда я пытаюсь запустить что-то не работает с детьми.
Полная реализация здесь:https://courses.cs.washington.edu/courses/cse446/12wi/ps/hw4/ID3.java
Я сделал некоторые изменения для моей цели.
Заранее спасибо.
Джузеппе.

-2

Решение

Спасибо Гийому Рацико за советы!
Это код:
В Node.cpp:

class Node
{
public:
Node();
Node(Node* parent, std::vector<Instance>& instances);
Node* parent;
std::vector<Node*> children;
....
};

Node::Node(Node* parent, std::vector<Instance>& instances) {

this->parent = parent;
this->children= std::vector<Node*>(Instance::FTSVALUERANGE);
...
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector