diff --git a/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md b/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md index 55325a6764..05d49f218c 100644 --- a/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md +++ b/client/src/pages/guide/english/algorithms/sorting-algorithms/bubble-sort/index.md @@ -114,17 +114,20 @@ void bubblesort(int arr[], int n) { if(n==1) //Initial Case return; - + bool swap_flag = false; for(int i=0;iarr[i+1]) { - temp=arr[i]; + int temp=arr[i]; arr[i]=arr[i+1]; arr[i+1]=temp; + swap_flag = true; } } - + // IF no two elements were swapped in the loop, then return, as array is sorted + if(swap_flag == false) + return; bubblesort(arr,n-1); //Recursion for remaining array } ```