0

So i found a code thats the Java equivalent of the bubble sort algorithm, i understand parts of it, but the thing is i dont get how it works, specifically the loops which i assume do much of the work, can somebody please explain to me, i swear if i had 1 thousand dollars i would give to you if you explained well, but all i got is points to give... sooo pleaase i know its tedious but again pleease:

public class Bubble {

public static void main (String args[]){
System.out.println("Bubble sort algorithm:");
int name [] = {7,3,4,20,6};

for(int x = 0; x<name.length;x++){
System.out.print(name[x] + " ");}

for (int x = name.length-1; x > 0; x-- ){
for(int y = 0; y < name.length-1; y++){
int temp = name[y];
int tempo = name[y+1];
if(name[y]>name[y+1]){
name[y]=tempo;
name[y+1]=temp;

}	
}}

System.out.println();
for(int x=0; x<name.length;x++){
System.out.print(name[x]+ " ");

}


}

}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by thekashyap
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.