¿Cóm se ordena un array?

¿Cóm se ordena un array?

Postby fleal » Wed Oct 26, 2005 3:45 pm

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
fleal
 
Posts: 234
Joined: Tue Oct 25, 2005 12:39 am
Location: México, DF

Postby DanielPuente » Thu Oct 27, 2005 1:08 am

Fernando:

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

Saludos,
Daniel Puente
Mar del Plata, Argentina
danielpuente@speedy.com.ar
puenteda@hotmail.com
DanielPuente
 
Posts: 108
Joined: Sun Oct 09, 2005 6:12 pm
Location: Mar del Plata - Argentina

Postby fleal » Thu Oct 27, 2005 3:07 am

Contiene valores simples.

Gracias
Fernando Leal
fleal
 
Posts: 234
Joined: Tue Oct 25, 2005 12:39 am
Location: México, DF

Postby DanielPuente » Thu Oct 27, 2005 12:43 pm

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,
Daniel Puente
Mar del Plata, Argentina
danielpuente@speedy.com.ar
puenteda@hotmail.com
DanielPuente
 
Posts: 108
Joined: Sun Oct 09, 2005 6:12 pm
Location: Mar del Plata - Argentina

Postby fleal » Thu Oct 27, 2005 3:51 pm

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
fleal
 
Posts: 234
Joined: Tue Oct 25, 2005 12:39 am
Location: México, DF

Postby DanielPuente » Fri Oct 28, 2005 1:35 am

Fernando:

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

Saludos,
Daniel Puente
Mar del Plata, Argentina
danielpuente@speedy.com.ar
puenteda@hotmail.com
DanielPuente
 
Posts: 108
Joined: Sun Oct 09, 2005 6:12 pm
Location: Mar del Plata - Argentina

Re: ¿Cóm se ordena un array?

Postby fleal » Sat Oct 29, 2005 4:46 pm

Funciona bien,
gracias


Saludos
Fernando Leal
México, DF
fleal
 
Posts: 234
Joined: Tue Oct 25, 2005 12:39 am
Location: México, DF


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 35 guests