+ 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
4 Antworten
+ 10
@shobhit
check this code: Selection Sort
https://code.sololearn.com/c15piBCsHY70/?ref=app
+ 7
Just Need Some Movement :
if(arr[j]>max) {
max = arr[j];
swap = arr[i];
arr[i] = max;
arr[j] = swap;
}
+ 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.