Page 1 of 1

¿Cóm se ordena un array?

PostPosted: Wed Oct 26, 2005 3:45 pm
by fleal
Tengo el siguiente código que me ordena por el primer elemento, luego por el segundo.

aResumen := ASort( aResumen, , , { | x, y | If( x[1] < y[1], .T., If( x[1] == y[1], x[2] < y[2], FALSE ) ) } )


Pero no he conseguido ordenar por el tercer elemento

Saludos
Fernando Leal
México, DF

PostPosted: Thu Oct 27, 2005 1:08 am
by DanielPuente
Fernando:

Que tipo de informacion contiene el array, valores simples o son arrays anidados ?.

Saludos,

PostPosted: Thu Oct 27, 2005 3:07 am
by fleal
Contiene valores simples.

Gracias
Fernando Leal

PostPosted: Thu Oct 27, 2005 12:43 pm
by DanielPuente
Fernando:

Si contiene valores simples no necesitas pasarle el criterio de ordenacion como parametro por cada uno de los elementos. Con poner:

aMatriz := { 3, 5, 1, 2, 4 }
ASORT(aMatriz)
//Resultado: { 1, 2, 3, 4, 5 }

ASORT(aMatriz,,, { |x, y| x > y })
//Resultado: { 5, 4, 3, 2, 1 }

Es suficiente, fijate en las NG.

Saludos,

PostPosted: Thu Oct 27, 2005 3:51 pm
by fleal
Daniel,
Perdona... es así como se contruye el array.

while HISTORIA->( !eof() )
AADD( aResumen,{ HISTORIA->CLAVE_VERI, HISTORIA->CPRODUCTO, HISTORIA->ID_VERIF, HISTORIA->ID_ZONA, 1 } )
HISTORIA->( DbSkip() )
enddo

Como ves, recorro la HISTORIA.DBF y voy agregando al array 4 campos y el al quinto solo le pongo el número 1

Pues, necesito ordenar por CLAVE_VERI despues por CPRODUCTO hasta aquí no tengo problemas, pero no he podido subordernar por ID_VERIF Y ID_ZONA

Saludos
Fernando

PostPosted: Fri Oct 28, 2005 1:35 am
by DanielPuente
Fernando:

aResumen:=ASORT(aResumen,,,{ |x,y| x[1]+x[2]+x[3]+x[4] < y[1]+y[2]+y[3]+y[4] } )

Saludos,

Re: ¿Cóm se ordena un array?

PostPosted: Sat Oct 29, 2005 4:46 pm
by fleal
Funciona bien,
gracias


Saludos
Fernando Leal
México, DF