Created
October 9, 2017 01:55
-
-
Save qzm/74d4a7b4f993689fc6951f2175b16bb6 to your computer and use it in GitHub Desktop.
quick sort
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
| function quickSort(arr) { | |
| if (arr.length <= 1) { | |
| return arr; | |
| } | |
| var mid = [arr[0]]; | |
| var left = []; | |
| var right = []; | |
| for (var i = 1; i < arr.length; i++) { | |
| if (arr[i] <= mid[0]) { | |
| left.push(arr[i]); | |
| } else { | |
| right.push(arr[i]); | |
| } | |
| } | |
| return quickSort(left).concat(mid, quickSort(right)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment