C # bubbling Algorithm review
Bubble algorithm Meaning: Each trip to find a minimum or maximum number to the last side, compare the total number of n-1 times (because the comparison is 2 both compare)
The second loop represents the first few loops, the number of trips equals the number of comparisons-the number of times (the second trip is less than once, because the smallest one after the first trip)
usingSystem;namespacetest{classProgram { Public Static voidMain () {//bubble algorithm Meaning: Each trip to find a minimum or maximum number put to the last side, compare the total number of n-1 times inttemp; int[] arr = { at, A, $, -, the, $, the, -, $, -}; //The first layer of loops represents the number of comparisons that are to be compared (number of)-1 times for(intI=0; I<arr. length-1; i++) { //The second loop represents the first few loops, the number of trips equals the comparison-the number of trips (starting from 1) (the second trip is less than once, because the smallest after the first trip is the last one) for(intj=0; J<arr. length-1-I.; J + +) { if(Arr[j] > arr[j+1]) {temp=Arr[j]; ARR[J]= arr[j+1]; Arr[j+1] =temp; } } } foreach(intNincharr) {Console.WriteLine (n); } console.readkey (); } }}
C # bubbling Algorithm review