Bubble sort: void Bubble(Itemtype a[], int N ) { int i, j; for (i = N - 1; i > 0; --i) for (j = 1; j <= i; ++j) if (a[j-1] > a[j]) swap(a[j-1],a[j]; } To increase the efficiency of this sort, need to check to see if a swap has been done. Add the boolean variable DidSwap and change the program to: DidSwap = true; for (i = N-1; DidSwap && i > 0; i--) { DidSwap = false; for (j = 1; j <= i; ++j) if (a[j-1] > a[j]) { DidSwap = true; swap(a[j],a[j-1]; } } Insertion sort: void Insertion(ItemType a[], int N) { int i, j; ItemType v; for (i = 1; i < N; ++i) { v = a[i]; j = i; while (j > 0 && a[j-1] > v) { a[j] = a[j-1]; j = j-1; } a[j] = v; } } Selection sort: void selection( ItemType a[], int N) { int i, j, min; for (i = 0; i < N-1; ++i) { //Elements from 0 to i-1 are in the correct place min = i; for (j = i+1; j < N; ++j) if (a[j] < a[min]) min = j; swap(a[i], a[min]); //Elements from 0 to i are in the correct place } } Merge Sort: void merge(ItemType a[]; ItemType temp[]; int left; int mid; int right) { int i = left, j = mid, k = left; while (i < mid && j <= right) { if (a[i] <= a[j]) { temp[k] = a[i]; i++; } else { temp[k] = a[j]; j++; } k++ } while (i < mid) { temp[k] = a[i]; k++; i++; } while (j <= right) { temp[k] = a[j]; k++; j++; } for (i = left; i <= right; ++i) a[i] = temp[i]; } QuickSort: The first call to Quicksort is Quicksort(a, 0, N-1); void Quicksort(ItemType a[], int left, int right) { int i, j; ItemType v; if (right > left) { v = a[right]; i = left - 1; j = right; do { do i = i + 1; while ( a[i] < v); do j = j - 1; while (j >= left && a[j] > v); if (i < j) swap(a[i], a[j]); } while (j > i); swap(a[i], a[right]); Quicksort(a, left, i-1); Quicksort(a, i+1, right); } }