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
// An Example of a bubble sort algorithm in Swift | |
// | |
// Essentialy this algorithm will loop through the values up to | |
// the index where we last did a sort (everything above is already in order/sorted) | |
// comparing a one value to the value before it. If the value before it is higher, | |
// swap them, and note the highest swap index. On the next iteration of the loop we | |
// only need to go as high as the previous swap. | |
import Foundation |
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 Foundation | |
// Build 100 random numbers between 0 and 100 | |
var numbers = Int[]() | |
for i in 1..100 { | |
let n = Int(arc4random() % 101) | |
numbers.append(n) | |
} | |
func elementsInRange<T>(a: T[], start: Int, end: Int) -> (T[]) { |
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
var randomNumbers = [42, 12, 88, 62, 63, 56, 1, 77, 88, 97, 97, 20, 45, 91, 62, 2, 15, 31, 59, 5] | |
func partition(v: Int[], left: Int, right: Int) -> Int { | |
var i = left | |
for j in (left + 1)..(right + 1) { | |
if v[j] < v[left] { | |
i += 1 | |
(v[i], v[j]) = (v[j], v[i]) | |
} | |
} |
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
void audioRouteChangeListenerCallback ( | |
void *inUserData, | |
AudioSessionPropertyID inPropertyID, | |
UInt32 inPropertyValueSize, | |
const void *inPropertyValue | |
) { | |
// ensure that this callback was invoked for a route change | |
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return; | |
if ([inUserData isKindOfClass:[IVAudioPlayerController class]]) { |