Hallo, sieht jemand den Fehler, bzw weiß jemand was geändert gehört?
Fehlermeldung ist:
| c = System.out.printf("count: %d, value%d%n", c+1 ,node.value);
incompatible types: java.io.PrintStream cannot be converted to int
Fehlermeldung ist:
| c = System.out.printf("count: %d, value%d%n", c+1 ,node.value);
incompatible types: java.io.PrintStream cannot be converted to int
Java:
//
class Node {
int value;
Node left;
Node right;
Node(int value) {
this.value = value;
}
}
class Tree {
int c;
Node root;
void add(int value) {
root = addNode(root, value);
}
Node addNode(Node node, int value) {
if (node==null) {
return new Node(value);
}
if (value < node.value) {
node.left = addNode(node.left, value);
}
else if (value > node.value) {
node.right = addNode(node.right, value);
}
else {
return node;
}
return node;
}
int descending(Node node) {
if (node != null) {
c = this.descending(node.right);
c = System.out.printf("count: %d, value%d%n", c+1 ,node.value);
c ++;
c = this.descending(node.left);
}
return c;
}
void Inorder() {
this.Inorder(root);
}
void Inorder(Node node) {
if (root != null) {
this.Inorder(node.left);
System.out.println(node.value);
this.Inorder(node.right);
}
}
}
Zuletzt bearbeitet: