Skip to content

Instantly share code, notes, and snippets.

@SanjeevMohindra
Last active January 2, 2017 03:31
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 SanjeevMohindra/24063b1469de738961d313bb2092edd0 to your computer and use it in GitHub Desktop.
Save SanjeevMohindra/24063b1469de738961d313bb2092edd0 to your computer and use it in GitHub Desktop.
//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