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; }
sorts in inefficient way?
:)
yeah I think that's the bubble sort.
It is bubble sort .It sorts the array of numbers in order .
ur write Tomas.A . It sorts in inefficient way.Hate bubble sort... quick sort is better according to me .
it's not because of bubble sort inefficiency, it's because even bubble sort algorhitm is implemented inefficient :D
:) 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.
you can google better algorhitm more quickly :D
See, for just 30 items and one time sort, efficiency is overkill. :)
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
@GT i dont understand u wat do u mean by 30 items?
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.
Join our real-time social learning platform and learn together with your friends!