Created
November 26, 2018 19:35
-
-
Save ranmyfriend/3906e2abb2bc2b3587e43288e9e54575 to your computer and use it in GitHub Desktop.
This file contains 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
//Using C function in Swift | |
var numbers = [50,4,13,2,1] | |
func quickSort(input: inout [Int]) { | |
qsort(&input, input.count, MemoryLayout<Int>.size) { (l,r) -> Int32 in | |
if let left = l?.assumingMemoryBound(to: Int.self), | |
let right = r?.assumingMemoryBound(to: Int.self) { | |
if left.pointee < right.pointee { | |
return -1 | |
}else if left.pointee == right.pointee { | |
return 0 | |
}else { | |
return 1 | |
} | |
} | |
return 0 | |
} | |
} | |
print(numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment