Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/10/2011, 12:04
el_shinito
 
Fecha de Ingreso: mayo-2011
Mensajes: 4
Antigüedad: 13 años
Puntos: 0
Pregunta Medir tiempo de Algoritmo

Necesito tomar el tiempo que toma Aplicar el Algoritmo de BubbleSort en cada uno de los 3 vectores, los cuales uno esta ordenado Aleatoriamente(V1), V2 esta Ascendente y V3 Descendente, he imprimir los resultados en un .Txt no tengo idea de si existe una función ya en java para medir el tiempo el milisegundos, y como se escribe exactamente en un txt con java ...

Cita:
public static void main(String[] args) throws IOException
{
int N,j,p,i;
int V1[]= new int [30];
int V2[]= new int [30];
int V3[]= new int [30];

Random rn = new Random();


BufferedReader entrada=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Dame el total de numeros a ordenar: ");
N=Integer.parseInt(entrada.readLine());


for(i=0;i<N;i++)
V1[i]=i+1;
for(j=1; j<=N; j++)
{
do
{
p= rn.nextInt(40);
} while(V1[p] !=0);
V1[p]=j;
}

j=1;
for(i=0; i<N; i++)
{
V2[i]=j;
j++;
}

j=N;
for(i=0; i<N; i++)
{
V3[i]=j;
j--;
}

public static void BubbleSort(int A[], int N)
{
int i,j,aux;

for(i=0; i<N; i++)
for (j=N-1; j>i+1; j--)
{
if(A[j] < A[j-1])
{ aux=A[j];
A[j]=A[j-1];
A[j-1]=aux;
}
}
}

De Antemano Muchas gracias por su ayuda.