Skip to content

Instantly share code, notes, and snippets.

@visparashar
Created September 10, 2017 16:14
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 visparashar/d18c8751f27e866c7fc08a1af1b07d38 to your computer and use it in GitHub Desktop.
Save visparashar/d18c8751f27e866c7fc08a1af1b07d38 to your computer and use it in GitHub Desktop.
Java Implemenation of BubbleSort
/*
*
@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