#include using namespace std; /** * Swap element i and j in array arr. */ void swap(int arr[], int i, int j) { int tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; } /* * Implemented from psuedocode at wikipedia. * See: http://en.wikipedia.org/wiki/Bubble_sort * * returns the number of comparisons performed to sort the list. */ int bubbleSort(int arr[], int n) { int numComparisons = 0; bool swapped; do { swapped = false; for (int i=0;i arr[i+1]) { swap(arr,i,i+1); swapped = true; } } } while (swapped); return numComparisons; } string toString(int arr[], int n) { string s = "{"; for (int i=0;i