### 冒泡排序和選擇排序(C++實現）

``void bubblesort(int arr[], int sz){    int i, j;    for (i = 0; i < sz; i++)    {        for (j = 1; j < sz - i; j++)        {            if ((arr[j-1]) >(arr[j]))            {                int tmp = 0;                tmp = arr[j-1];                arr[j-1] = arr[j];                arr[j] = tmp;            }        }    }}int main(){    int arr[10] = { 10, 8, 9, 5, 4, 3, 1, 2, 7, 6 };    int sz = sizeof(arr) / sizeof(arr[0]);    bubblesort(arr, sz);    int i = 0;    for (i = 0; i < sz; i++)    {        cout << arr[i] << " ";    }    system("pause");    return 0;}``

``void SelectSort(int *a, int len){    for (int i = 0; i<len - 1; i++)    {        int k = i;        int key = a[i];        for (int j = i + 1; j<len; j++)        {            if (a[j]<key)            {                k = j;                key = a[j];            }        }        if (k != i)            swap(a[i], a[k]);    }}int main(){    int arr[10] = { 10, 8, 9, 5, 4, 3, 1, 2, 7, 6 };    int sz = sizeof(arr) / sizeof(arr[0]);    SelectSort(arr, sz);    int i = 0;    for (i = 0; i < sz; i++)    {        cout << arr[i] << " ";    }    system("pause");    return 0;}``