Created
September 10, 2017 16:14
-
-
Save visparashar/d18c8751f27e866c7fc08a1af1b07d38 to your computer and use it in GitHub Desktop.
Java Implemenation of BubbleSort
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
/* | |
* | |
@author noeik | |
* | |
*/ | |
public class BubbleSort { | |
static int[] data = {10,23,45,5,3,2};// global data integer array | |
public static void main(String[] args) { | |
sort(data); | |
display(); | |
} | |
//main sort method | |
public static void sort(int[] data) | |
{ | |
for(int i =0;i<data.length-1;i++) | |
{ | |
for(int j=0;j<data.length-1-i;j++) | |
{ | |
if(data[j]>data[j+1]) | |
{ | |
int temp =data[j+1]; | |
data[j+1] =data[j]; | |
data[j] =temp; | |
} | |
} | |
} | |
} | |
// display method to show the array | |
public static void display() | |
{ | |
String result = "["; | |
for(int d :data) | |
{ | |
result = result +d+","; | |
} | |
result =result+"]"; | |
System.out.println(result); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment