我正在使用ID3算法,其中一个要求是我将父级和子级添加到此类而不进行修改。我不确定最好的方法吗?有没有人有任何想法?
class Tree {
Tree[] children;
int value;
public Tree(Tree[] ch, int val) {
value = val;
children = ch;
} // constructor
public String toString() {
return toString("");
} // toString()
String toString(String indent) {
if (children != null) {
String s = "";
for (int i = 0; i < children.length; i++)
s += indent + data[0][value] + "=" + strings[value][i] + "\n" + children[i].toString(indent + '\t');
return s;
} else
return indent + "Class: " + strings[attributes - 1][value] + "\n";
} // toString(String)
} // inner class Tree