+ 1
anyone help please
array A contains the following values: 2 3 4 4 10 4 5 6 12 9. as I understand it, the condition will work only once: the four and two change their places with each other. There is no element in the array smaller than two. THEN WHY IN THE DECISION, THE CONDITION WORKS ON TWO TIMES STILL ?? why s = 3, but not s = 1 ?? https://code.sololearn.com/c86nZq738qlJ/?ref=app
4 ответов
+ 3
Thank you, guys🌌 i got it
+ 2
Because you are swapping with condition
A[i] <=A[n]
Swapping when
A[0]<=A[3] =>2<=4
A[3]<=A[3] =>2<=2
A[5]<=A[3] =>4<=4
So should be it A[i] <A[n] only...
+ 2
After first swap A[3] = 2, but i = 1
when A becomes 3 (on fourth iteration) condition is also true:
A[3] <= A[3] is true (2 <= 2)
it is second swap, after which A[3] = 4
when i becomes 5 A[5] = 4 condition is again true:
A[5] <= A[3] (4 < = 4)
it is third swap.
so s = 3.