Tehát, az orvosom azt kérdezik tőlem, hogy végre treeSort (), majd tesztelje azt int [1000000] és kiszámítja az idő.
Van osztály BSTree<E>, amely tartalmazza az alábbi módszerekkel:
public void treeSort(E[] data)
{
inorder(data, new Process<E>(), root);
}
public static <E> void inorder(E[] list, Process<E> proc, BTNode<E> p)
{
if (p != null)
{
inorder(list, proc, p.getLeft( )); // Traverse its left subtree
proc.append(list, p.getElement( )); // Process the node
inorder(list, proc, p.getRight( )); // Traverse its right subtree
}
}
és én Process<E>osztály:
public class Process<E>
{
private int counter = 0;
public void append(E[] list, E element)
{
list[counter] = element;
counter++;
}
}
és én a következő Mainosztály:
public class Main
{
public static void main(String[] args)
{
int[] temp = {4,2,6,4,5,2,9,7,11,0,-1,4,-5};
treeSort(temp);
for(int s : temp) System.out.println(s);
}
public static void treeSort(int[] data)
{
BSTree<Integer> tree = new BSTree<Integer>();
for(int i: data) tree.insert(i);
tree.inorder(data, new Process<Integer>(), tree.getRoot()); // I get an error here!
}
}
A hiba a következő:
cannot find symbol - method inorder(int[], Process<java.lang.Integer>, BTNode<java.lang.Integer>); maybe you meant: inorder(E[], Process<E>, BTNode<E>);
Én fix, hogy megváltoztatja treeSort(int[] data)az treeSort(Integer[] data). De van egy hiba a fő módszertreeSort(temp);
és a hiba:
treeSort(java.lang.Integer) in Main cannot be applied to (int[])
Szóval, hogyan tudom kezelni ezt a kérdést, figyelembe véve nem növeli a komplexitás idő, amikor meg kell próbálnia ezt a módszert fel 1 millió bemenet?













