![]() | ||||||||||||||
|
Bubble SortCheck out the "Improved Bubble Sort"Please refer to Section 8.2.2 (p. 180). Check out this code
go_on=1;
for (int end=n-1; go_on && end > 0; end=end-1)
{ go_on=0;
for (int i=0; i < end; i=i+1)
{ if (a[i] > a[i+1])
{ temp=a[i+1]; a[i+1]=a[i]; a[i]=temp; go_on=i; } <--
}
}
Explain why go_on=i; on the code line marked by (<--) will still work if changed to go_on=1;. And say why that is not as efficient. | |||||||||||||
| back to demos | | ||||||||||||||