Java - Método de ordenamiento Quick - no ordena bien los datos (listas enlazadas)

 
Vista:

Método de ordenamiento Quick - no ordena bien los datos (listas enlazadas)

Publicado por Jose Luis (2 intervenciones) el 18/11/2015 21:47:54

Este es el código:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public void quick(int first, int last){
	i = first;
	j = last;
	k=(i+j)/2;
	tmp = primero;
	for(n=0;n<=k;n++){
		tmp = tmp.getEnlace();
	}
	pivote = tmp.getDato();
	while(i<=j){
		aux = primero;
		while(aux.getDato()<pivote){
			aux = aux.getEnlace();
			i=i+1;
		}
		tmp = fin;
		while(tmp.getDato()>pivote){
			j=j-1;
			tmp = primero;
			for(n=0; n<=j;n++){
				try{
					tmp = tmp.getEnlace();
				}
				catch(Exception e){
					n=j+1;
				}
			}
		}
		if(i<=j){
			backup = aux.getDato();
			aux.setDato(tmp.getDato());
			aux = tmp;
			aux.setDato(backup);
			i=i+1;
			j=j+1;
			aux = primero;
			for (n=0;n<=i;n++) {
				aux = aux.getEnlace();
			}
			tmp = primero;
			for(n=0; n<=j;n++){
				tmp = tmp.getEnlace();
			}
		}
	}
	if(first<j)
		quick(first, j);
	if(i<last)
		quick(i, last);
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder