sort code in cPP code example
Example 1: c++ buble sort
void bubbleSort(int arr[], int size){
int temp = int();
for ( int i = 0; i < size -1; i ++)
cout << arr[i] << "\t";
cout << endl << endl;
for (int i = 1; i < size; i++ ){
for(int j = 0; j < size - i ; j ++){
if( arr[j] > arr[j + 1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
Example 2: c++ buble sort
Psuedo code:
Procedure bubble_sort (array , N)
array – list of items to be sorted
N – size of array
begin
swapped = false
repeat
for I = 1 to N-1
if array[i-1] > array[i] then
swap array[i-1] and array[i]
swapped = true
end if
end for
until not swapped
end procedure