Last active
January 8, 2018 17:30
-
-
Save kiaratto/e60514668cbf2e3b726d8e21f0dd9c89 to your computer and use it in GitHub Desktop.
Ordenação de List ou Array na Raça no Salesforce APEX , a lógica pode-se utilizar para qualquer linguagem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//============================================================================ | |
//Autor:Rodrigo Chiarato Domingues - RodrigoChiarato@gmail.com | |
//Data: 08/01/2017 | |
//Descrição: Exemplo de código Ordena Array ou List | |
//Obs: Código em Apex do Salesforce mas a lógica serve para qualquer linguagem | |
//============================================================================ | |
string[] dd = new string[]{'ab','cd','fg','aa','bc','ba'}; | |
string[] ordenado = new list<string>(); | |
ordenado.add(dd[0]); | |
integer posicao = 0; | |
for(string f : dd){ | |
if(f == ordenado[0] ) continue; | |
posicao = 0; | |
for(integer i=0 ; i < ordenado.size() ; i++) | |
{ | |
if(f > ordenado[i] ) { | |
posicao = i+1; | |
} | |
} | |
if(posicao == ordenado.size()) | |
{ | |
ordenado.add(f); | |
} | |
else { | |
ordenado.add(posicao, f); | |
} | |
} | |
system.debug(ordenado); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment