HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>Welcome to the first chapter of the sorting algorithms course! Here, you will learn about bubble sort and put this algorithm into practice.</p>
1 <p>Welcome to the first chapter of the sorting algorithms course! Here, you will learn about bubble sort and put this algorithm into practice.</p>
2 <p><b>How to Complete This Chapter</b></p>
2 <p><b>How to Complete This Chapter</b></p>
3 <ol><li>Check out this<a>interactive tutorial</a>on bubble sort.</li>
3 <ol><li>Check out this<a>interactive tutorial</a>on bubble sort.</li>
4 <li>Come back and complete this practice task to track your progress.</li>
4 <li>Come back and complete this practice task to track your progress.</li>
5 <li>Sharpen your skills with<a>variable practice</a>.</li>
5 <li>Sharpen your skills with<a>variable practice</a>.</li>
6 </ol><p><b>Your Task</b></p>
6 </ol><p><b>Your Task</b></p>
7 <p>Fix the sorting function so that the states of the array during sorting match the sample. You need to add the code that swaps the array elements.</p>
7 <p>Fix the sorting function so that the states of the array during sorting match the sample. You need to add the code that swaps the array elements.</p>
8 <p>To view the sample or test your program, click the button Boss, here’s your program!</p>
8 <p>To view the sample or test your program, click the button Boss, here’s your program!</p>
9 <p><strong>Solution</strong></p>
9 <p><strong>Solution</strong></p>
10 <p>The solution to the challenge will be available in a few minutes. Use it if you encounter difficulties. In the meantime, try to complete the challenge on your own.</p>
10 <p>The solution to the challenge will be available in a few minutes. Use it if you encounter difficulties. In the meantime, try to complete the challenge on your own.</p>
11 let arr = [4, 6, 8, 1, 7]; draw(arr); bubbleSort(arr); function bubbleSort(arr) { let n = arr.length - 1; for (let pass = 0; pass &lt; n; pass++) { for (let j = 0; j &lt; n - pass; j++) { if (arr[j] &gt; arr[j + 1]) { let temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; draw(arr, j, j + 1); } } } }
11 let arr = [4, 6, 8, 1, 7]; draw(arr); bubbleSort(arr); function bubbleSort(arr) { let n = arr.length - 1; for (let pass = 0; pass &lt; n; pass++) { for (let j = 0; j &lt; n - pass; j++) { if (arr[j] &gt; arr[j + 1]) { let temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; draw(arr, j, j + 1); } } } }