Tak, mój lekarz pytając mnie do wdrożenia Treesort (), a następnie przetestować go na int [1000000] i obliczyć czas.
Mam klasy BSTree<E>, która zawiera następujące 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
}
}
i mam Process<E>klasę:
public class Process<E>
{
private int counter = 0;
public void append(E[] list, E element)
{
list[counter] = element;
counter++;
}
}
i mam następujące Mainklasy:
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!
}
}
Błąd jest:
cannot find symbol - method inorder(int[], Process<java.lang.Integer>, BTNode<java.lang.Integer>); maybe you meant: inorder(E[], Process<E>, BTNode<E>);
Naprawiłem że zmieniając treeSort(int[] data)się treeSort(Integer[] data). Ale mam błąd w głównym sposobem natreeSort(temp);
a błąd jest:
treeSort(java.lang.Integer) in Main cannot be applied to (int[])
Tak, jak można sobie radzić z tym problemem z uwzględnieniem nie zwiększając czas złożoność gdzie powinienem spróbować tej metody na 1 milion wejść?













