+ 3

why this is not sorting elements?

it instead swaps every index with biggest number of full array https://code.sololearn.com/cBwZx6iyyqej/?ref=app

7th Jan 2018, 1:56 PM
shobhit
shobhit - avatar
4 Answers
+ 10
@shobhit check this code: Selection Sort https://code.sololearn.com/c15piBCsHY70/?ref=app
7th Jan 2018, 4:54 PM
ZeroByte
ZeroByte - avatar
+ 7
Just Need Some Movement : if(arr[j]>max) { max = arr[j]; swap = arr[i]; arr[i] = max; arr[j] = swap; }
7th Jan 2018, 2:04 PM
ZeroByte
ZeroByte - avatar
+ 1
but while executing that if block, i dont know which is the biggest number. and thats what it does it iterates over every element and check if its biggers 0th index. and then after that swaps it with arr[i]. acc to you r answer it would swap numbers before finding the biggest number.
7th Jan 2018, 3:57 PM
shobhit
shobhit - avatar