Problemas con la implementación de Treesort ()

votos
1

Por lo tanto, mi doctor me pide que implementar Treesort () y luego probarlo en int [1000000] y calcular el tiempo.

Tengo la clase BSTree<E>que contiene los siguientes métodos:

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
    }
}

y tengo Process<E>clase:

public class Process<E>
{
    private int counter = 0;
    public void append(E[] list, E element)
    {
        list[counter] = element;
        counter++;
    }
}

y tengo la siguiente Mainclase:

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!
    }
}

El error es:

cannot find symbol - method inorder(int[], Process<java.lang.Integer>, BTNode<java.lang.Integer>); maybe you meant: inorder(E[], Process<E>, BTNode<E>);

Me fijo que cambiando treeSort(int[] data)a treeSort(Integer[] data). Pero tengo un error en el método principal entreeSort(temp);

y el error es:

treeSort(java.lang.Integer) in Main cannot be applied to (int[])

Así que, ¿cómo puedo hacer frente a este problema con la toma en cuenta no el aumento de la complejidad de tiempo donde debería probar este método en 1 millón de entradas?

Publicado el 19/05/2011 a las 13:49
fuente por usuario
En otros idiomas...                            


2 respuestas

votos
0

Los genéricos no puede haber clases básicas. Puede utilizar Entero [] en lugar de int [], y se basan en autoboxing.

Respondida el 19/05/2011 a las 13:54
fuente por usuario

votos
1

Entero [] temp = {4,2,6,4,5,2,9,7,11,0, -1,4, -5};

EDIT: utilizarlo para fijar segundo error.

Respondida el 19/05/2011 a las 13:56
fuente por usuario

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more