Array, Bubble sorting, simplified, and simplified array Bubble Sorting
// Int array [] = {3, 2, 6, 9, 8, 5, 7, 1, 4 };
// Int count = sizeof (array)/sizeof (array [0]);
// Int flag = 1;
// For (int I = 0; I <count-1 & flag = 1; I ++ ){
// Flag = 0;
// For (int j = 0; j <count-I-1; j ++ ){
// If (array [j]> array [j + 1]) {
// Int temp = array [j];
// Array [j] = array [j + 1];
// Array [j + 1] = temp;
// Flag = 1;
//}
//}
//}
// For (int I = 0; I <count; I ++ ){
// Printf ("array [% d] = % d \ n", I, array [I]);
//}
Sort any array in JAVA bubble
This is the bubble sort ~~~!
Public class Sort_Bubble {
Public static void main (String [] args ){
Int [] arr = };
For (int I = arr. length-1; I> = 0; I --){
For (int j = 0; j <I; j ++ ){
If (arr [j]> arr [j + 1]) {
Int temp = arr [j];
Arr [j] = arr [j + 1];
Arr [j + 1] = temp;
}
}
}
// View the result ~~
For (int I = 0; I <arr. length; I ++ ){
System. out. print (arr [I] + "");
}
}
}
Sort the following arrays by bubble sort
I guess the code I wrote was written in Java. I wrote a Java Applet named Sort. java.
The Code is as follows:
Public class Sort {
Public static void sort (String [] s ){
For (int I = 0; I <s. length-1; I ++ ){
String temp;
For (int j = 0; j <s. length-I-1; j ++ ){
If (s [j]. compareTo (s [j + 1])> 0 ){
Temp = s [j + 1];
S [j + 1] = s [j];
S [j] = temp;
}
}
}
}
Public static void main (String [] args ){
String [] arr = {"Now", "is", "the", "time", "for", "all", "good", "men ",
"To", "come", "to", "the", "aid", "of", "their", "country"
};
Sort (arr );
For (int I = 0; I <arr. length; I ++ ){
System. out. println (arr [I]);
}
}
}