Skip to content

Instantly share code, notes, and snippets.

@Ronnasayd
Created November 8, 2020 17:20
Show Gist options
  • Save Ronnasayd/be12e3b47770bc02efa004da8f8ba5b5 to your computer and use it in GitHub Desktop.
Save Ronnasayd/be12e3b47770bc02efa004da8f8ba5b5 to your computer and use it in GitHub Desktop.
Implementação de algoritmos e estrutura de dados
// 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