Created
January 4, 2017 03:11
-
-
Save trilliwon/49f40bac1fe6bac64336f181ed3306b6 to your computer and use it in GitHub Desktop.
InsertionSort in swift
This file contains hidden or 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
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