Last active
August 12, 2016 09:04
-
-
Save SanjeevMohindra/18330fd95b3a537fd0db8c097fab1784 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 in Java | |
public static void bubbleSort(int[] inputData) { | |
int inputDataLength = inputData.length; | |
while (inputDataLength != 0) { | |
int newn = 0; | |
for (int forwardPointer = 1; forwardPointer < inputData.length - 1; forwardPointer++) { | |
if(inputData[forwardPointer - 1] > inputData[forwardPointer]) { | |
final int 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