0
Selection sort
I am not getting the array in sorted format I guess logic is correct . If not please help me out https://code.sololearn.com/ca5a15A18a22
4 ответов
+ 4
First of all, you forgot to reset "flag" to false at the start of the outer loop, and for the outer loop it is sufficient to check if 'i' is smaller than size - 1.
The main issue is that you forgot to update "min" inside the if statement. Right now, you would swap the current element with the last number smaller than it, which is not necessarily the smallest number in the sequence left (consider [3, 1, 2] as an example). Inside the conditional, you need to assign "min" the value of arr[ j ], to reflect the currently smallest value.
+ 3
Because you are not resetting "flag" to false at the start of the outer loop, as mentioned earlier.
+ 1
Shadow
Thanks for your help
But still the 44 is not getting swapped with 35
+ 1
Thank you so much for your help
Need to clear some basics