No. You clear a flag and exit early if the flag is still clear:
Code:for(i=0;i<total-1; i++){ flag = 0; for (j=0;j<total-1;j++){ if (array[j]>array[j+]) { swap(array[j],array[j+1]); flag = 1; } } if (flag==0) break; // exit early }
|
Results 1 to 5 of 5
Thread: Bubble sort functionalityHybrid View
|
Click Here to Expand Forum to Full Width |