In the past, we used sorting methods in other languages. Other algorithms are the same regardless of the language. They are simply processed using a temporary variable or some built-in functions.
In the past, we used sorting methods in other languages. Other algorithms are the same regardless of the language. They are simply processed using a temporary variable or some built-in functions.
Public class CharuSort {
Public static void main (String [] args ){
Int [] sort = {4, 6, 3, 9, 5 };
Sort (sort );
For (int I = 0; I <sort. length; I ++)
System. out. print (sort [I] + "");
}
Public static void Sort (int [] sort ){
Int I; // indicates the number of scans.
Int j; // specifies the comparison element.
For (I = 1; I <sort. length; I ++) {// Number of scans: sort. length-1
Int temp; // temp is used for temporary data storage.
Temp = sort [I];
J = I-1;
While (j> = 0 & temp <sort [j]) {// if the second element is smaller than the first element
Sort [j + 1] = sort [j]; // pushes all elements to a position.
J --;
}
Sort [j + 1] = temp; // place the smallest element in the first position.
}
}
}