Bubble sort lecture in arrays

Why was the iteration started from 1 and not from 0 i tried to use 0 in my code but there was some problem in my first element of the array i am not able to understand why?

you can start from any number but then you have to slightly change the inner loop exit condition

if you have start itr from 0 then
inner lop condition will be

CHECK THIS CODE


i have include both method here

i hope your doubt resolved now
if yes plz feedback from below link, it hardly takes a min
else feel free to ask

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like

MY doubt is why my first element is becoming 0 when i do n iterations because we know that n-1 iterations are sufficient for sorting but why on doing just one iteration more the first element is becoming 1 as i tried to dry run the code but not able to find out why is it becoming 1

yes
if you do n iteration then also it will work and give correct output
check the above code again
i have made n iteration now and it still works
plz check