Created
June 3, 2014 02:08
-
-
Save kimhunter/896ddfef6a47590ba2fe 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
import Cocoa | |
var nums: Int[] = [] | |
for var i = 0; i < 10; i++ { | |
nums.append(Int(arc4random()) % 200) | |
} | |
nums | |
func qSort(var arr: Int[]) -> Int[] { | |
if arr.isEmpty { | |
return arr | |
} | |
var pivot = arr.removeAtIndex(0) | |
var lower: Int[] = [] | |
var higher: Int[] = [] | |
for value in arr { | |
var isLower = value < pivot | |
if isLower { | |
lower.append(value) | |
} else { | |
higher.append(value) | |
} | |
} | |
return qSort(lower) + [pivot] + qSort(higher) | |
} | |
var a = qSort(nums) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment