Skip to content

Commit e36fca2

Browse files
committed
feat: support for already sorted arrays
1 parent 01a7f47 commit e36fca2

File tree

7 files changed

+22
-0
lines changed

7 files changed

+22
-0
lines changed

Diff for: bubble.js

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const bubbleSort = async function () {
3434
}
3535
document.getElementById("random-array").classList.remove("disabled");
3636
document.getElementById("reversed-array").classList.remove("disabled");
37+
document.getElementById("sorted-array").classList.remove("disabled");
3738
document.getElementById("size").classList.remove("disabled");
3839
document.getElementById("bubble").classList.toggle("active-btn");
3940
};

Diff for: index.html

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ <h1 class="h1" style="color: #183024;">Rotate Your Phone </h1>
7373
Reversed Array
7474
</button>
7575
</div>
76+
<div>
77+
<button class="btn btn-sm btn-clr" id="sorted-array" type="button">
78+
Sorted Array
79+
</button>
80+
</div>
7681
<div>
7782
<button class="btn btn-sm reload" id="reload">Reload</button>
7883
</div>

Diff for: insertion.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const insertionSort = async function () {
3838
}
3939
document.getElementById("random-array").classList.remove("disabled");
4040
document.getElementById("reversed-array").classList.remove("disabled");
41+
document.getElementById("sorted-array").classList.remove("disabled");
4142
document.getElementById("size").classList.remove("disabled");
4243
document.getElementById("insertion").classList.toggle("active-btn");
4344
};

Diff for: merge.js

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const mergeSort = async function () {
8484
await mergeS(0, Number(sz - 1)).then(() => doGreen(sz));
8585
document.getElementById("random-array").classList.remove("disabled");
8686
document.getElementById("reversed-array").classList.remove("disabled");
87+
document.getElementById("sorted-array").classList.remove("disabled");
8788
document.getElementById("size").classList.remove("disabled");
8889
document.getElementById("merge").classList.toggle("active-btn");
8990
};

Diff for: quick.js

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const quickSort = async function () {
9292
await quickS(0, Number(sz - 1)).then(() => doGreen(sz));
9393
document.getElementById("random-array").classList.remove("disabled");
9494
document.getElementById("reversed-array").classList.remove("disabled");
95+
document.getElementById("sorted-array").classList.remove("disabled");
9596
document.getElementById("size").classList.remove("disabled");
9697
document.getElementById("quick").classList.toggle("active-btn");
9798
};

Diff for: selection.js

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const selectionSort = async function () {
6868
}
6969
document.getElementById("random-array").classList.remove("disabled");
7070
document.getElementById("reversed-array").classList.remove("disabled");
71+
document.getElementById("sorted-array").classList.remove("disabled");
7172
document.getElementById("size").classList.remove("disabled");
7273
document.getElementById("selection").classList.toggle("active-btn");
7374
};

Diff for: sorting.js

+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const sizeSlider = document.getElementById("size");
55
// const barsRect = barsEl.getBoundingClientRect();
66
const btnRandomArray = document.getElementById("random-array");
77
const btnReversedArray = document.getElementById("reversed-array");
8+
const btnSortedArray = document.getElementById("sorted-array");
89
const btnReload = document.getElementById("reload");
910
// const barsWidth = barsRect.width;
1011
// const barsHeight = barsRect.height;
@@ -14,6 +15,14 @@ const barsHeight = barsEl.offsetHeight;
1415
barsEl.innerHTML = "";
1516
let bars = [];
1617

18+
const sortedArray = function () {
19+
bars = [];
20+
for (let i = 1; i <= sizeSlider.value; ++i) {
21+
bars.push(i);
22+
}
23+
plantArray()
24+
}
25+
1726
const reversedArray = function () {
1827
bars = [];
1928
for (let i = sizeSlider.value; i > 0; --i) {
@@ -79,6 +88,7 @@ const swap = function (bar1, bar2) {
7988
const tempDisable = function () {
8089
document.getElementById("random-array").classList.add("disabled");
8190
document.getElementById("reversed-array").classList.add("disabled");
91+
document.getElementById("sorted-array").classList.add("disabled");
8292
document.getElementById("size").classList.add("disabled");
8393
document.getElementById("bubble").classList.add("disabled");
8494
document.getElementById("merge").classList.add("disabled");
@@ -90,6 +100,7 @@ const tempDisable = function () {
90100
const tempEnable = function () {
91101
document.getElementById("random-array").classList.remove("disabled");
92102
document.getElementById("reversed-array").classList.remove("disabled");
103+
document.getElementById("sorted-array").classList.remove("disabled");
93104
document.getElementById("size").classList.remove("disabled");
94105
document.getElementById("bubble").classList.remove("disabled");
95106
document.getElementById("merge").classList.remove("disabled");
@@ -100,4 +111,5 @@ const tempEnable = function () {
100111

101112
btnRandomArray.addEventListener("click", randomArray);
102113
btnReversedArray.addEventListener("click", reversedArray);
114+
btnSortedArray.addEventListener("click", sortedArray);
103115
btnReload.addEventListener("click", () => location.reload());

0 commit comments

Comments
 (0)