A sorting algorithm is a basic and common algorithm. Sorting algorithms are classified into internal sorting and external sorting.
Internal sorting means that the entire sorting process can be completed without accessing external storage.
External sorting means that when the party sorts a large volume of data, it is impossible to load all the data into the memory at a time. It can only read a part of the data from the external memory to the memory. After sorting the data in the memory, store the data in the external store, read the next part of the data from the external store to the memory, and merge and sort the sorted sub-parts.
Bubble Sorting is a sort method for adjacent data exchanges. The characteristics of Bubble sorting are that n elements need to be scanned for n-1 times, so sometimes the data may be scanned once or twice before sorting is completed, and subsequent scanning is obviously a waste of computing resources, so you can improve the Bubble Sorting by using the following code:
Public class bubblesort {public void bubblesort (INT [] In) {Boolean isbubble = false; int inlength = in. length; For (INT I = 0; I <inlength; I ++) {system. out. print ("no." + I + "Times:"); For (int K: In) {system. out. print (K + "");} system. out. println (); For (Int J = inlength-1; j> I; j --) {If (in [J] <in [J-1]) {isbubble = true; int TMP = in [J]; In [J] = in [J-1]; In [J-1] = TMP ;}} if (! Isbubble) {break;} else {isbubble = false ;}} public static void main (string [] ARGs) {bubblesort mbubblesort = new bubblesort (); int [] caseone = {6, 5, 4, 3, 2, 1, 10, 2}; int [] casetwo = {1, 6, 5, 2, 4, 3}; mbubblesort. bubblesort (caseone); For (int I: caseone) {system. out. print (I + "");} system. out. println (); mbubblesort. bubblesort (casetwo); For (int I: casetwo) {system. out. print (I + "");}}}