Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

What does this code do: int main() { float list[30]; float temp = 0; int i = 0; int j = 0; while (i<30) { scanf("%f\n", &list[i++]); } for (i=0; i<30; i++) { for (j=0; j<30; j++) { if (list[i] < list[j]) { temp = list[i]; list[i] = list[j]; list[j] = temp; } } } for (i=0; i<30; i++) { printf("%0.3f\n", list[i]); } return 1; }

OpenStudy (anonymous):

sorts in inefficient way?

OpenStudy (anonymous):

:)

OpenStudy (anonymous):

yeah I think that's the bubble sort.

OpenStudy (anonymous):

It is bubble sort .It sorts the array of numbers in order .

OpenStudy (anonymous):

ur write Tomas.A . It sorts in inefficient way.Hate bubble sort... quick sort is better according to me .

OpenStudy (anonymous):

it's not because of bubble sort inefficiency, it's because even bubble sort algorhitm is implemented inefficient :D

OpenStudy (anonymous):

:) Exactly. I swap same items over and over in it. It is a bad algorithm. But, I wrote it quickly for sorting 30 floating point numbers my son had for homework.

OpenStudy (anonymous):

you can google better algorhitm more quickly :D

OpenStudy (anonymous):

See, for just 30 items and one time sort, efficiency is overkill. :)

OpenStudy (anonymous):

But linear insertion sort/shellsort is the most efficient of the "easy to code/small code size O(n^2)" sorting algorithms..., but yeah bubblesort is probably even simpler than those

OpenStudy (anonymous):

@GT i dont understand u wat do u mean by 30 items?

OpenStudy (anonymous):

My son's homework had 30 numbers (decimals) to sort. So, I just wrote this silly program with an array of 30 to sort those numbers.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!