1void bubbleSort(int arr[], int size){
2 int temp = int();
3 //print out the unsorted values
4 for ( int i = 0; i < size -1; i ++)
5 cout << arr[i] << "\t";
6 cout << endl << endl;
7
8
9 for (int i = 1; i < size; i++ ){
10 for(int j = 0; j < size - i ; j ++){//size-i is the sorted part of the array
11 if( arr[j] > arr[j + 1]){//if the value is greater than the next value in the array, swap it
12 temp = arr[j];
13 arr[j] = arr[j+1];//swap the two values
14 arr[j+1] = temp;
15
16 }//end if
17 }//end for
18 }//end for
19
20}//end bubbleSort
1Psuedo code:
2
3Procedure bubble_sort (array , N)
4 array – list of items to be sorted
5 N – size of array
6begin
7 swapped = false
8 repeat
9 for I = 1 to N-1
10 if array[i-1] > array[i] then
11 swap array[i-1] and array[i]
12 swapped = true
13 end if
14 end for
15 until not swapped
16end procedure