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; } } }
2 Antworten
+ 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
0
Yeah It just a snippet,
Plz assume and explain clearly..