Skip to content

Instantly share code, notes, and snippets.

@bonoogi
Last active August 15, 2022 02:08
Show Gist options
  • Save bonoogi/8771e6e338ab18d7b4ca39357f913461 to your computer and use it in GitHub Desktop.
Save bonoogi/8771e6e338ab18d7b4ca39357f913461 to your computer and use it in GitHub Desktop.
지겨운 정렬 알고리즘...넣어두고 필요할떄 꺼내먹자
func quickSort(_ array: [Int]) -> [Int] {
guard array.count > 1 else { return array }
let pivot = array.first!
var left = [Int]()
var right = [Int]()
for i in 1..<array.count {
let value = array[i]
if value < pivot {
left.append(value)
} else {
right.append(value)
}
}
return quickSort(left) + [pivot] + quickSort(right)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment