Skip to content

Instantly share code, notes, and snippets.

@VictorKid
Created May 27, 2016 01:30
Show Gist options
  • Save VictorKid/8dfabf52679135d384199bcb2d98d2ff to your computer and use it in GitHub Desktop.
Save VictorKid/8dfabf52679135d384199bcb2d98d2ff to your computer and use it in GitHub Desktop.
func quickSort(sortElms: [Int]) -> [Int] {
let arr = sortElms
guard arr.count > 0 else {
return arr
}
let first = arr.first
let left = arr.filter({$0 < first})
let right = arr.filter({$0 > first})
return quickSort(left)+[first!]+quickSort(right)
}
let sortElms = [13423, 234, 243, 234, 234, 56, 56, 7778, 56756, 2, 3, 0, 8, 9, 7, 30043587943, 34523789, 342578945, 2323]
let quickSortResult = quickSort(sortElms)
print("quickSortResult: \(quickSortResult)")
// result
// [0, 2, 3, 7, 8, 9, 56, 234, 243, 2323, 7778, 13423, 56756, 34523789, 342578945, 30043587943]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment