+ 9
Sotring algorithm
when I try to code the bubble sorting by myself after the explination I reach that code https://code.sololearn.com/c2Rt89ZLvT0D/?ref=app but I thing it is not a real bubble where is the wrong
6 odpowiedzi
+ 1
* Actually you don't need to return the sorted array, because arrays are implemented in objects in java, thus you are passing array arguments by reference not by value(primitive types are passed by value).
* in Bubble sort, you don't need to test all array elements every iteration, just first iteration enough. that's why you will see the condition of second for block adjusted to j<=in.length - i
+ 3
I but it to block unhelpful iteration
can you give me an example
+ 1
It's exactly bubblesort just delete line 21 "if(x==0)break;" that`s wrong.if u exchange 4 and 5 places in array u will see it doesn't work because of that command
+ 1
check this there it is same as your but with little bit more clear , in second loop you can start were you ended the first one , like j=i
0
I adjusted your code as following:
https://code.sololearn.com/cR6jdRFoldli/?ref=app