Yury Posted November 30, 2007 Report Share Posted November 30, 2007 olá pessoal, imaginem uma tabela multidimensional com os seguintes dados: aTabela:={ { 2100, 10, 2 },; { 1200, 10, 2 },; { 1200, 10, 3 },; { 1200, 20, 1 },; { 1200, 30, 1 },; { 1200, 40, 1 },; { 3350, 20, 2 },; { 2100, 20, 1 },; { 2100, 30, 1 },; { 2100, 10, 1 },; { 3350, 20, 1 } } id=code>id=code>gostaria de fazer um ASORT em ordem crescente pelo 1º elemento e decrescente pelo 2º e 3º elementos, para que ela fique assim: aTabela:={ { 1200, 40, 1 },; { 1200, 30, 1 },; { 1200, 20, 1 },; { 1200, 10, 3 },; { 1200, 10, 2 },; { 2100, 30, 1 },; { 2100, 20, 1 },; { 2100, 10, 2 },; { 2100, 10, 1 },; { 3350, 20, 2 },; { 3350, 20, 1 } } id=code>id=code>tentei da forma abaixo mas não ordenou... ASORT(aTabela,,,{|a,b| a[1] < b[1].and.; a[2] > b[2].and.; a[3] > b[3] }) id=code>id=code>será q é possÃvel ? obrigado e um abraço Yury Marcelino Al Viman Sistemas vimansca@vimansca.com.br yury030575@yahoo.com.br (msn) skype: yury.marcelino.al Leme / SP FW 2.6 / [x]Harbour 99.50 / WS / xDev 0.65 / @say Quote Link to comment Share on other sites More sharing options...
Yury Posted November 30, 2007 Author Report Share Posted November 30, 2007 olá pessoal, imaginem uma tabela multidimensional com os seguintes dados: aTabela:={ { 2100, 10, 2 },; { 1200, 10, 2 },; { 1200, 10, 3 },; { 1200, 20, 1 },; { 1200, 30, 1 },; { 1200, 40, 1 },; { 3350, 20, 2 },; { 2100, 20, 1 },; { 2100, 30, 1 },; { 2100, 10, 1 },; { 3350, 20, 1 } } id=code>id=code>gostaria de fazer um ASORT em ordem crescente pelo 1º elemento e decrescente pelo 2º e 3º elementos, para que ela fique assim: aTabela:={ { 1200, 40, 1 },; { 1200, 30, 1 },; { 1200, 20, 1 },; { 1200, 10, 3 },; { 1200, 10, 2 },; { 2100, 30, 1 },; { 2100, 20, 1 },; { 2100, 10, 2 },; { 2100, 10, 1 },; { 3350, 20, 2 },; { 3350, 20, 1 } } id=code>id=code>tentei da forma abaixo mas não ordenou... ASORT(aTabela,,,{|a,b| a[1] < b[1].and.; a[2] > b[2].and.; a[3] > b[3] }) id=code>id=code>será q é possÃvel ? obrigado e um abraço Yury Marcelino Al Viman Sistemas vimansca@vimansca.com.br yury030575@yahoo.com.br (msn) skype: yury.marcelino.al Leme / SP FW 2.6 / [x]Harbour 99.50 / WS / xDev 0.65 / @say Quote Link to comment Share on other sites More sharing options...
Geraldo (gbsilva) Posted November 30, 2007 Report Share Posted November 30, 2007 Yury tente assim: ASORT(aTabela,,,{|x,y,z| x[1]+x[2]+x[3] < y[1]+y[2]+y[3] }) Um abraço, Geraldo B. Silva FWH 2.6 Junho/2005, xHarbour 0.99.50 (Simplex), Bcc55, Pelles, xDev, MyMake, Sqllib e MySql. lucgera@terra.com.br São Paulo - SP Quote Link to comment Share on other sites More sharing options...
Geraldo (gbsilva) Posted November 30, 2007 Report Share Posted November 30, 2007 Corrigindo... ASORT(aTabela,,,{|x,y| x[1]+x[2]+x[3] < y[1]+y[2]+y[3] }) Geraldo B. Silva FWH 2.6 Junho/2005, xHarbour 0.99.50 (Simplex), Bcc55, Pelles, xDev, MyMake, Sqllib e MySql. lucgera@terra.com.br São Paulo - SP Quote Link to comment Share on other sites More sharing options...
Yury Posted November 30, 2007 Author Report Share Posted November 30, 2007 olá Geraldo, obrigado pela resposta... mas assim não dá certo, pois preciso de ordenação em dois sentidos, crescente e decrescente... desta forma q vc passou funcionaria se a ordenação de todos os elementos fossem no mesmo sentido... obrigado e um abraço Yury Marcelino Al Viman Sistemas vimansca@vimansca.com.br yury030575@yahoo.com.br (msn) skype: yury.marcelino.al Leme / SP FW 2.6 / [x]Harbour 99.50 / WS / xDev 0.65 / @say Quote Link to comment Share on other sites More sharing options...
Geraldo (gbsilva) Posted November 30, 2007 Report Share Posted November 30, 2007 E assim: ASORT(aTabela,,,{|x,y| x[1] < y[1] .and. x[2]+x[3] > y[2]+y[3] }) Sei lá hehehehe é chutômetro. Geraldo B. Silva FWH 2.6 Junho/2005, xHarbour 0.99.50 (Simplex), Bcc55, Pelles, xDev, MyMake, Sqllib e MySql. lucgera@terra.com.br São Paulo - SP Quote Link to comment Share on other sites More sharing options...
gibaf Posted November 30, 2007 Report Share Posted November 30, 2007 tente assim: aSort( aTabela,,, { |x, y | x[1]+descend(x[2]) < y[1]+descend(y[2]) } ) Att Gilberto Frohlich - Toledo/PR giba_f@hotmail.com giba_f@yahoo.com.br xHarbour Comercial xBuild Mar_06+Fivewin 2.7+PellesC+(Postgres+DB2) Quote Link to comment Share on other sites More sharing options...
jarmo Posted December 1, 2007 Report Share Posted December 1, 2007 Yury, as vezes a resposta está tão perto de você que você nem percebe - ah ah ah! Veja: uma maneira simples de resolver isto: na gravação do 2º e 3º elemento, faça com que eles fiquem com sinal invertido, ou seja negativo, multiplique por -1 e utilize a função aSort sem se preocupar com ordem crescente ou descendente; espero ter ajudado. José Ap.R.M.Oliveira Viman Sistemas vimansca@vimansca.com.br Leme / SP FW 2.6 / [x]Harbour 99.50 / WS / xDev 0.65 / @say Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.