以下のコードでは、次のエラーが発生します。
SearchTree.java:19: error: 'void' type not allowed here
this.setRoot(this.insertgt(this.insertionSort(value)));
どうしたの?
コード:
import java.util.Arrays;
public class SearchTree {
private TreeNode root;
private static int sum = 0;
public void setRoot(TreeNode n){
this.root = n;
}
public TreeNode getRoot(){
return this.root;
}
// returns a SearchTree
public void insert(int[] value) {
System.out.println(value == null);
this.setRoot(this.insertgt(this.insertionSort(value)));
}
public void insertgt(int[] value) {
if (value.length == 0) return;
TreeNode currentNode;
currentNode.left = new TreeNode(ArrayMinimum.minimum(value));
if (value.length > 0) {
currentNode = new TreeNode(insertgt(value));
currentNode.right = new TreeNode(insertgt(value));
}
return currentNode;
}
// returns sum of node.values
public int sum() {
if (this.left == null && this.right == null) return sum;
sum = this.value + sum;
if (this.left != null && this.right != null) {
sum = this.left.sum();
sum = this.right.sum();
}
}
// returns number of nodes
public int numberOfLeafs() {
if (this.left == null && this.right == null)
return(1 + this.left.numberOfLeafs() + this.right.numberOfLeafs());
return(1 + this.left.numberOfLeafs() + this.right.numberOfLeafs() );
}
// returns zahl if searchTree contains zahl
public int search(int zahl) {
if (this.value == zahl) return null;
return(1 + this.left.search(zahl) + this.right.search(zahl));
}
public int[] insertionSort(int[] data) {
for(int i = 1; i < data.length; i++) {
int t = data[i];
int j = i - 1;
while(j >= 0 && data[j] > t) {
data[j + 1] = data[j];
j--;
}
data[j + 1] = t;
}
return data;
}
}
class ArrayMinimum {
// removes and returns the minimum element
static int minimum(int [] v) {
int min = v[0];
for (int i = 0; i < v.length; i++) {
if (v[i] < min) {
min = v[i];
}
}
ArrayUtils.remove(value, min);
return min;
}
}