The algorithm needs to master the simple bubble sort words not much to say we look at the following:
/** * Put a chaotic array int arr[] = {2,2323,23,456,1,342}; * According to the order that we often say the sort of counterfeit * or as we have said before when we encounter problems, we dismembered the problem. * 1, first we want to put a chaotic array into order, we should first find out the largest (or the smallest) * 2, and then we sequentially follow the method of the loop can be arranged out of the order of the want, the idea has been, to achieve it! * @author Administrator * */public class bubblesorted {public static int arr[] = {2,2323,23,456,1,342};p ublic static void Main (string[] args) {test (arr);} public static void Test (int arr[]) {//First find the biggest idea in terms of what we say from arr[]: Think about it now you have a glass of water. Coffee how to swap the liquid in two cups? You're smart to take another cup! Come on, then. Because considering the length of the array may often be used to extract him into variables. int len = arr.length;//in order to make this sort method more efficient we can make a decision to join the loop again when there is no change in the row position we stop looping the Boolean boo = true;for (int j =0;j<len-1;j++) {Bo o = true;//assumes ordered System.out.println ("the" + (j+1) + "trip"); for (int i =0;i<len-1-j;i++) {System.out.println ("+" + (i+1) + "th"); if (arr[i]<arr[i+1]) {int temp = arr[i];//pour water into the temp cup arr[i] = arr[i+1];//Pour the coffee into the cup that just started to water arr[i+1] = temp;// Finally pour the water from the Temp Cup into the cup in which the coffe is just beginning. Boo = false;//If there is a change, place Boo as false}system.out.println (arr);} if (boo) {break;}}}}Do the right thing when you don't know what to do.
Algorithm--Simple bubble sort