Created
October 30, 2016 20:39
-
-
Save seyhunak/45c390d6321690c8ee9c84e7eae1908e to your computer and use it in GitHub Desktop.
Bubble Sort Algoritm in Swift
This file contains 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 | |
func bubbleSort(inout numbers: [Int]) -> () { | |
let numbersLength = numbers.count | |
for i in 0 ..< numbersLength { | |
for j in 1 ..< numbersLength-i { | |
if numbers[j-1] > numbers[j] { | |
let swap = numbers[j-1] | |
numbers[j-1] = numbers[j] | |
numbers[j] = swap | |
} | |
} | |
} | |
} | |
var numbers = [5, 15, 14, 1, 6, 26, 5, 76, 99] | |
bubbleSort(&numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment