Last active
January 2, 2017 03:31
-
-
Save SanjeevMohindra/24063b1469de738961d313bb2092edd0 to your computer and use it in GitHub Desktop.
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
//Bubble Sort Algorithm | |
func bubbleSort(inputData: inout [Int]) { | |
var inputDataLength = inputData.count | |
while inputDataLength != 0 { | |
var newn = 0 | |
for forwardPointer in 1...inputDataLength - 1 { | |
if (inputData[forwardPointer - 1] > inputData[forwardPointer]) { | |
let temp = inputData[forwardPointer - 1] | |
inputData[forwardPointer - 1] = inputData[forwardPointer] | |
inputData[forwardPointer] = temp | |
newn = forwardPointer | |
} | |
} | |
inputDataLength = newn | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment