Why? what happens? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Why? what happens?

Why the function sort() does not work as expected to? What happens during the execution of the code? How can we fix this bug? .... static void sort(int[] arr) { int a = 0; for(int i : arr) { int b = 0; for(int j : arr) { if(i > j) { arr[a] = j; arr[b] = i; } b++; } a++; } } .... https://code.sololearn.com/ceMAVa9M15fM/?ref=app

24th Dec 2022, 11:40 PM
Abd Alwahab Alansi
Abd Alwahab Alansi - avatar
1 ответ
0
You are missing a temporary variable to save the value of the old position for the new position. That is why the final values ​​are repeated
25th Dec 2022, 12:14 AM
Teddy Alejandro Moreira Vélez
Teddy Alejandro Moreira Vélez - avatar