Created
November 8, 2020 17:20
-
-
Save Ronnasayd/be12e3b47770bc02efa004da8f8ba5b5 to your computer and use it in GitHub Desktop.
Implementação de algoritmos e estrutura de dados
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
// Insertion sort | |
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
list := []int{5, 2, 4, 6, 1, 3} | |
for j := 1; j < len(list); j++ { | |
chave := list[j] | |
i := j - 1 | |
for i >= 0 && list[i] > chave { | |
list[i+1] = list[i] | |
i = i - 1 | |
} | |
list[i+1] = chave | |
} | |
fmt.Printf("%s - %v", "lista ordenada:", list) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment