HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>We’ve practiced element-swapping enough. Let’s summarize why an auxiliary variable is needed. Suppose there is an array in which we swap the first and second elements without the auxiliary variable:</p>
1 <p>We’ve practiced element-swapping enough. Let’s summarize why an auxiliary variable is needed. Suppose there is an array in which we swap the first and second elements without the auxiliary variable:</p>
2 var numbers = [1, 2, 3]; // Now numbers are [2, 2, 3] numbers[0] = numbers[1];<p>If we immediately write the value of the second element in the first place, we will lose the value of the first element. Therefore, you first you need to store the value of the first element in a variable:</p>
2 var numbers = [1, 2, 3]; // Now numbers are [2, 2, 3] numbers[0] = numbers[1];<p>If we immediately write the value of the second element in the first place, we will lose the value of the first element. Therefore, you first you need to store the value of the first element in a variable:</p>
3 var numbers = [1, 2, 3]; // Now 1 is stored in swap var swap = numbers[0]; // Now numbers are [2, 2, 3] numbers[0] = numbers[1]; // Now numbers are [2, 1, 3] numbers[1] = swap;<p>The next step on the way to sorting is to search for the minimum element. And we will look for this element not in the whole array, but in its specified part.</p>
3 var numbers = [1, 2, 3]; // Now 1 is stored in swap var swap = numbers[0]; // Now numbers are [2, 2, 3] numbers[0] = numbers[1]; // Now numbers are [2, 1, 3] numbers[1] = swap;<p>The next step on the way to sorting is to search for the minimum element. And we will look for this element not in the whole array, but in its specified part.</p>
4 <p>To do this, let’s set up variable currentIndex. It will control the initial value of the loop variable. Note that the loop variable this time will be called j (this is another typical name).</p>
4 <p>To do this, let’s set up variable currentIndex. It will control the initial value of the loop variable. Note that the loop variable this time will be called j (this is another typical name).</p>