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: // This is the code for the merge sort itself. In order to use it, the // merge function needs to be added. It needs to take the two sorted arrays // and combine them into a single sorted array. void merge_sort(int a[], int from, int to) { if (from == to) return; int mid = (from + to) / 2; // Sort the first and the second half merge_sort(a, from, mid); merge_sort(a, mid + 1, to); merge(a, from, mid, to); } 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); } } Index Sort in place: * The array Data[0],...,Data[N-1] is to be rearranged in place as directed by the index array Index[0],...,Index[N-1]. That is, the data in Data[0] is supposed to be in Data[Index[0]]. Any element with Index[i] == i is in place and does not need to be touched again. Otherwise, save Data[i] as V and work through the cycle Index[i], Index[Index[i]] and so on, until reaching the index i again. Follow the process again for the next element which is not in place, and continue in this manner, ultimately rearranging the entire array, moving each record only once. Reference: "Algorithms in C++", Third Edition, Robert Sedgewick, pg. 306 */ void Insitu(ItemType Data[], int Index[], int N) { int i, j, k; ItemType V; for (i = 0; i < N; i++) { V = Data[i]; for (k = i; Index[k] != i; k = Index[j], Index[j] = j) { j = k; Data[k] = Data[Index[k]]; } Data[k] = V; Index[k] = k; } }