0

Anyone plz explain the following code clearly?

This program is for sorting array values in descending order.. boolean flag =true; int temp; While(flag) { flag =false; for(int i=0;i<array.length-1;i++){ if(sortedArray[i]<sortedArray[i+1]{ temp=sortedArray[i]; sortedArray[i] =sortedArray[i+1]; sortedArray[i+1]=temp; flag=true; } } }

4th Mar 2017, 12:42 PM
Srinath G
Srinath G - avatar
2 ответов
+ 1
well i think the biggest issue is its definitely not complete, for one there's no closing } but i assume that's just a code snippet that's cut off, but the bigger issue is (again need more code) as is its an infinite loop. its technique is fine if closed correctly, does a compare to next array item and if less than, swaps the two in sequence. depending on the size of the array might be slow but it works if closed properly
6th Mar 2017, 10:24 AM
William La Flamme
William La Flamme - avatar
0
Yeah It just a snippet, Plz assume and explain clearly..
6th Mar 2017, 12:37 PM
Srinath G
Srinath G - avatar