Skip to content

Instantly share code, notes, and snippets.

@MickhailP
Created January 10, 2023 19:30
Show Gist options
  • Save MickhailP/b33b572aad15da5de7001e5a76f335eb to your computer and use it in GitHub Desktop.
Save MickhailP/b33b572aad15da5de7001e5a76f335eb to your computer and use it in GitHub Desktop.
AlgorithmsQuickSort
func quickSort(nums: [Int]) -> [Int] {
if nums.count < 2 {
return nums
} else {
let pivot = nums[0]
var lessPart: [Int] = []
var greaterPart: [Int] = []
for i in 1..<nums.count {
if nums[i] <= pivot {
lessPart.append(nums[i])
} else {
greaterPart.append(nums[i])
}
}
return quickSort(nums: lessPart) + [pivot] + quickSort(nums: greaterPart)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment