650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0057.gif "alt=" j_0057.gif "/> bubble sort: (e.g. ascending)
In the first order, starting with the first element, the entire sequence of elements to be sorted is scanned, and if the adjacent two elements are reversed, the position is swapped. Until the last element, at this point, the last element must be the largest element.
The second order is still scanned from the first element until the second element is the penultimate one.
The third order, from the first scan to the penultimate one.
......
Until only one element remains to be scanned.
The procedure is as follows:
#include <stdio.h>int main () {int arr[]={1,2,3,9,8,7,5,6,4};int i=0;int j=0;int len=sizeof (arr)/sizeof (arr[0]); for (i=0;i<len;i++) {for (j=0;j<len-i;j++) {if (arr[j+1]<arr[j]) {int temp=arr[j];arr[j]=arr[j+1];arr[j+1]= temp;}}} for (i=0;i<len;i++) printf ("%d", Arr[i]); return 0;}
650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0059.gif "alt=" J_0059.gif "/> Simple and quick sort:
The first order, starting from the first element, selects the smallest element in the entire sequence, and the first element exchanges the position.
The second order, starting from the second element, selects the smallest, and second, swap position.
......
The procedure is as follows:
#include <stdio.h>int main () {int arr[]={1,2,3,9,8,7,5,6,4};int i=0;int j=0;int k=0;for (i=0;i<sizeof (arr)/ sizeof (Arr[0]) -1;i++) {k=i;for (j=i+1;j<sizeof (arr)/sizeof (Arr[0]); j + +) {if (arr[j]<arr[k]) k=j;} if (k!=i) {int temp=arr[i];arr[i]=arr[k];arr[k]=temp;}} For (i=0;i<sizeof (arr)/sizeof (arr[0]); i++) printf ("%d", Arr[i]); return 0;}
Bubble sort and simple selection sort