Java Bubble Sorting
C # There are more than N sorting types. Here we paste the most EASY Bubble sorting and Bubble Sorting: the comparison of I and I + 1 in the array. After N-times of comparison, the array elements can be sorted according to our expectation. In descending order, we use the numbers less than signs <1, 2, 3, 4, 5, 6, and 7 to compare the original data with seven elements, 2, 3, 4, 5, 6, and 7, 1 The first trip compared 6 times 3, 4, 5, 6, 7, 2, 1 the second trip compared 5 times 4, 5, 6, 7, 3, 2, 1 the third trip compared 4 times 5, 6, 7, 4, 3, 2, 1 The fourth trip compared 3 times, 6, 5, 4, 3, 2, 1 the fifth trip compared 2 times, 7, 6, 5, 4, 3, 2, 1 sixth trip compared 1 times that N number needs to take the N-1 trip t the number of times compared is N-t how to come to this conclusion, this is similar to finding a formula for the number of equal-to-difference series in mathematics. TRY, then u got it. I = 0 first I = 1 second number of bytes: t = I + 1 instance:
Int [] scores = {15, 26, 10, 67, 77,123,100,123, 2, 70, 65,544,100}; for (int I = 0; I <scores. length-1; I ++) // control the number of compare records. This loop controls the number of records {for (int j = 0; j <scores. length-i-1; j ++) // control the number of comparisons per trip {if (scores [j] <scores [j + 1]) // compare the element size in each trip {int temp = scores [j]; scores [j] = scores [j + 1]; scores [j + 1] = temp ;}} foreach (int k in scores) {Console. writeLine (k);} Console. readKey ();
I believe that algorithms may not always be used in the actual bytecode (cainiao --!), But it can expand your thinking and improve your understanding of the Code. Eight sort algorithms: round (this cow B): http://ahalei.blog.51cto.com/