Takže, můj lékař mě ptá realizovat treeSort () a poté ji vyzkoušet na int [1000000] a vypočítat čas.
Mám třídu BSTree<E>, která obsahuje následující metody:
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
}
}
a mám Process<E>třída:
public class Process<E>
{
private int counter = 0;
public void append(E[] list, E element)
{
list[counter] = element;
counter++;
}
}
a mám následující Maintřídy:
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!
}
}
Chyba je:
cannot find symbol - method inorder(int[], Process<java.lang.Integer>, BTNode<java.lang.Integer>); maybe you meant: inorder(E[], Process<E>, BTNode<E>);
Opravil jsem, že změnou treeSort(int[] data)se treeSort(Integer[] data). Ale mám chybu v hlavní metodu natreeSort(temp);
a chyba je:
treeSort(java.lang.Integer) in Main cannot be applied to (int[])
Tak, jak mohu tento problém řešit s přihlédnutím nezvyšovat časovou složitost, kde bych měl vyzkoušet tuto metodu na 1 milion vstupů?













