Skip to content

Instantly share code, notes, and snippets.

View Vaberer's full-sized avatar

Patrick Vaberer Vaberer

View GitHub Profile
@Vaberer
Vaberer / QuickSort.swift
Last active August 29, 2015 14:27
Implementing Quick Sort with array of Integers
func quickSort(inout array: [Int], var leftIndex: Int = 0, var rightIndex: Int = -1) {
// O(n*log(n))
if rightIndex == -1 { //we can call quickSort without start and end index in the beginning so first time we will assign last index of the array to the variable
rightIndex = array.count - 1
}
var startLeftIndex = leftIndex
var startRightIndex = rightIndex
var pivot = array[leftIndex] //our pivot is the most left element
@Vaberer
Vaberer / QuickSort.swift
Created August 22, 2015 09:18
Implementing Quick Sort via Generics
func quickSort<T: Comparable>(inout array: [T], var leftIndex: Int = 0, var rightIndex: Int = -1) {
// O(n*log(n))
if rightIndex == -1 { //we can call quickSort without start and end index in the beginning so first time we will assign last index of the array to the variable
rightIndex = array.count - 1
}
var startLeftIndex = leftIndex
var startRightIndex = rightIndex
var pivot = array[leftIndex] //our pivot is the most left element