Last active
August 15, 2022 02:08
-
-
Save bonoogi/8771e6e338ab18d7b4ca39357f913461 to your computer and use it in GitHub Desktop.
지겨운 정렬 알고리즘...넣어두고 필요할떄 꺼내먹자
This file contains hidden or 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
| 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