Skip to content

Instantly share code, notes, and snippets.

@thatswiftguy
Created April 27, 2021 14:36
Show Gist options
  • Save thatswiftguy/efa1d8a9e27d56547558fc792f334598 to your computer and use it in GitHub Desktop.
Save thatswiftguy/efa1d8a9e27d56547558fc792f334598 to your computer and use it in GitHub Desktop.
Insertion sort in swift
var array1 = [3,4,1,6,7,2,5,5]
for i in 1..<array1.count {
let a = array1[i]
var b = i-1
while b >= 0 && array1[b] > a {
array1[b+1] = array1[b]
b -= 1
}
array1[b+1] = a
}
print(array1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment