diff --git a/bubble_sort b/bubble_sort new file mode 100644 index 0000000..1f10281 --- /dev/null +++ b/bubble_sort @@ -0,0 +1,66 @@ +*General Algorithm* +Step 1: For i = 0 to N-1 repeat Step 2 +Step 2: For J = i + 1 to N – I repeat + Step 3: if A[J] > A[i] +Swap A[J] and A[i] +[End of Inner for loop] +[End if Outer for loop] +Step 4: Exit +---------------------------------------------------------------------------- +*Pseudocode* +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 +--------------------------------------------------------------------------------- +*C++ Program* +#include +using namespace std; +int main () +{ + int i, j,temp,pass=0; + int a[10] = {10,2,0,14,43,25,18,1,5,45}; + cout <<"Input list ...\n"; + for(i = 0; i<10; i++) { + cout <