Skip to content

Commit 0c297b6

Browse files
Fixed Issue #3 and also fixed an mistake in selection sort
1 parent c95db84 commit 0c297b6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/sorting.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,16 @@ async function insertionSort(array) {
103103
document.getElementById("iterations").innerHTML = swaps;
104104
document.getElementById("time").innerHTML = time;
105105
}
106+
updateVisualisation(array);
107+
isRunning = false;
108+
if (isSorted(array)) {
109+
document.getElementById("isSorted").innerHTML = "True";
110+
}
106111
}
107112

108113
async function selectionSort(array) {
109114
let currentTimestamp = new Date().getTime();
110-
for (let i = 0; i < array.length - 2; i++) {
115+
for (let i = 0; i < array.length - 1; i++) {
111116
minmalElementIndex = i;
112117
for (let j = i + 1; j < array.length; j++) {
113118
if (gotReset) {
@@ -132,6 +137,12 @@ async function selectionSort(array) {
132137
array[minmalElementIndex] = array[i];
133138
array[i] = tmp;
134139
}
140+
if (array)
141+
updateVisualisation(array);
142+
isRunning = false;
143+
if (isSorted(array)) {
144+
document.getElementById("isSorted").innerHTML = "True";
145+
}
135146
}
136147

137148
function reset() {

0 commit comments

Comments
 (0)