Tuesday, July 28, 2009

Please send a C program involving bubble sorting....?

C programming

Please send a C program involving bubble sorting....?
Most programs avoid bubble sorts, as they become inefficient very quickly.





For very small lists, a bubble sort can work well, but it is best to avoid them.








Bubble sort:


for (i = 0; i %26lt; nItems-1; i++)


{


for (j = i+1; j %26lt; nItems; j++)


{


if (list(j) %26gt; list(i))


{


temp = list(i);


list(i) = list(j);


list(j) = temp;


}


}


}





Unfortunately Y!A doesn't allow proper indenting, so this looks a little messy, but it's still valid.


No comments:

Post a Comment