Created
April 27, 2021 14:36
-
-
Save thatswiftguy/efa1d8a9e27d56547558fc792f334598 to your computer and use it in GitHub Desktop.
Insertion sort 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
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