Skip to content

Instantly share code, notes, and snippets.

@kimhunter
Created June 3, 2014 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimhunter/896ddfef6a47590ba2fe to your computer and use it in GitHub Desktop.
Save kimhunter/896ddfef6a47590ba2fe to your computer and use it in GitHub Desktop.
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