Skip to content

Instantly share code, notes, and snippets.

@trilliwon
Created January 4, 2017 03:11
Show Gist options
  • Save trilliwon/49f40bac1fe6bac64336f181ed3306b6 to your computer and use it in GitHub Desktop.
Save trilliwon/49f40bac1fe6bac64336f181ed3306b6 to your computer and use it in GitHub Desktop.
InsertionSort in swift
import Foundation
func insertionSort(array: [Int]) -> [Int] {
var array = array
for index in 1..<array.count {
let nextValue = array[index]
var aux = index - 1
while aux >= 0 && array[aux] > nextValue {
swap(&array[aux+1], &array[aux])
aux -= 1
}
}
return array
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment