Skip to content

Instantly share code, notes, and snippets.

@ranmyfriend
Created November 26, 2018 19:35
Show Gist options
  • Save ranmyfriend/3906e2abb2bc2b3587e43288e9e54575 to your computer and use it in GitHub Desktop.
Save ranmyfriend/3906e2abb2bc2b3587e43288e9e54575 to your computer and use it in GitHub Desktop.
//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