Sort by bubble
Code
Package com. Qixin. Five;
Public class bubblesort {
Public static void main (string [] ARGs ){
Int [] array = new int };
Int temp;
System. Out. println ("original array content :");
Printarray (array );
For (INT I = 1; I <array. length; I ++ ){
For (Int J = 0; j <array. Length-I; j ++ ){
If (array [J]> array [J + 1]) {
Temp = array [J];
Array [J] = array [J + 1];
Array [J + 1] = temp;
}
}
}
System. Out. println ("result after ascending order :");
Printarray (array );
For (INT I = 1; I <array. length; I ++ ){
For (Int J = 0; j <array. Length-I; j ++ ){
If (array [J] <array [J + 1]) {
Temp = array [J];
Array [J] = array [J + 1];
Array [J + 1] = temp;
}
}
}
System. Out. println ("result after sorting from big to small :");
Printarray (array );
}
Public static void printarray (INT array []) {
For (int I: array ){
System. Out. Print (I + "");
}
System. Out. println ("\ n ");
}
}
Sort by selection
Code
Package com. Qixin. Five;
Public class selectsort {
Public static void main (string [] ARGs ){
Int [] array = new int };
Int temp;
System. Out. println ("original array content :");
Printarray (array );
Int index;
For (INT I = 1; I <array. length; I ++ ){
Index = 0;
For (Int J = 1; j <= array. Length-I; j ++ ){
If (array [J]> array [Index]) {
Index = J;
}
}
Temp = array [array. Length-I];
Array [array. Length-I] = array [Index];
Array [Index] = temp;
}
System. Out. println ("arrange the array content in the forward order :");
Printarray (array );
For (INT I = 1; I <array. length; I ++ ){
Index = 0;
For (Int J = 1; j <= array. Length-I; j ++ ){
If (array [J] <array [Index]) {
Index = J;
}
}
Temp = array [array. Length-I];
Array [array. Length-I] = array [Index];
Array [Index] = temp;
}
System. Out. println ("Inverted array content :");
Printarray (array );
}
Public static void printarray (INT [] array ){
For (int I: array ){
System. Out. Print (I + "");
}
}
}