02/21/00
COM1100 Winter2000 Yuhong Yin
13
Function BubbleSort()
n// This function will sort a given array in ascending order
n// and it will also return how many exchanges made in the process
nint BubbleSort(int list[], int size) {
n int move = 0; // move will record how many exchanges needed
n // totally, there will be size -1 passes
n for(int i = 0; i < size -1; i++) {
n //in each pass, there will be size-1 comparison
n for(int j =1; j < size; j++) {
n // check if exchange is needed
n if (list[j] < list[j-1]){
n swap(list[j], list[j-1]);
n move++;   }
n }
n }
n return move;
n}
n