Skip to content

Commit 613fb32

Browse files
committed
Update search algorithm by notification at bottom
1 parent 7d2e3fb commit 613fb32

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function swapBar(data) {
9999
function togglePlay() {
100100
var sortElement = document.getElementById("sort");
101101
var stopElement = document.getElementById("stop");
102-
if (isSorted) {
102+
if (isFound) {
103103
sortElement.classList.add("none");
104104
stopElement.classList.add("none");
105105
} else {

function.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var svg,
1111
unsortedColor = "#add8e6",
1212
sortedColor = "#56b4d3",
1313
isSorting = false,
14-
isSorted = false;
14+
isFound = false;
1515

1616
var swooshAudio = new Audio("./sound-effects/swoosh.mp3");
1717
var completeAudio = new Audio("./sound-effects/complete.mp3");
@@ -83,7 +83,7 @@ const SortAlgo = {
8383

8484
completeAudio.play();
8585
isSorting = false;
86-
isSorted = true;
86+
isFound = true;
8787
togglePlay();
8888
}
8989

@@ -143,7 +143,7 @@ const SortAlgo = {
143143

144144
completeAudio.play();
145145
isSorting = false;
146-
isSorted = true;
146+
isFound = true;
147147
togglePlay();
148148
}
149149
// calling sort function here
@@ -221,7 +221,7 @@ const SortAlgo = {
221221
svg.selectAll("rect").style("fill", "#56b4d3");
222222
completeAudio.play();
223223
isSorting = false;
224-
isSorted = true;
224+
isFound = true;
225225
togglePlay();
226226
}
227227

@@ -272,8 +272,8 @@ document.getElementById("random-data").addEventListener("click", function () {
272272
stopSorting();
273273
togglePlay();
274274
}
275-
if (isSorted) {
276-
isSorted = false;
275+
if (isFound) {
276+
isFound = false;
277277
document.getElementById("sort").classList.remove("none");
278278
}
279279
svg.remove();

searching-algorithm/base.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function swapBar(data) {
101101
function togglePlay() {
102102
var sortElement = document.getElementById("sort");
103103
var stopElement = document.getElementById("stop");
104-
if (isSorted) {
104+
if (isFound) {
105105
sortElement.classList.add("none");
106106
stopElement.classList.add("none");
107107
} else {

searching-algorithm/function.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var svg,
1111
unsortedColor = "#add8e6",
1212
sortedColor = "green",
1313
isSorting = false,
14-
isSorted = false;
14+
isFound = false;
1515

1616
var swooshAudio = new Audio("./../sound-effects/swoosh.mp3");
1717
var completeAudio = new Audio("./../sound-effects/complete.mp3");
@@ -63,7 +63,7 @@ const SearchAlgo = {
6363

6464
completeAudio.play();
6565
isSorting = false;
66-
isSorted = true;
66+
isFound = true;
6767
}
6868

6969
// calling async function here
@@ -88,7 +88,9 @@ const SearchAlgo = {
8888
changeBarColor(data[mid], traverseColor);
8989
if (data[mid] == target) {
9090
changeBarColor(data[mid], sortedColor);
91-
console.log("found");
91+
isFound = true;
92+
let text = target + " Found at position " + (mid + 1);
93+
document.getElementById("foundNotice").innerHTML = text;
9294
await timer(time);
9395
break;
9496
} else if (data[mid] < target) {
@@ -100,12 +102,15 @@ const SearchAlgo = {
100102

101103
await timer(time);
102104
}
105+
if (!isFound) {
106+
document.getElementById("foundNotice").innerHTML =
107+
target + " doesn't exist.";
108+
}
103109

104110
// after complete sorting complete making all the bar green and playing complete sound effects
105111

106112
completeAudio.play();
107113
isSorting = false;
108-
isSorted = true;
109114
}
110115

111116
// calling async function here
@@ -114,7 +119,7 @@ const SearchAlgo = {
114119
};
115120

116121
function startSearching() {
117-
algo = document.getElementById("get-algo").value;
122+
let algo = document.getElementById("get-algo").value;
118123
if (algo == "linear-search") {
119124
const linearSearchStarted = SearchAlgo.liearSearch.bind(SearchAlgo);
120125
linearSearchStarted();

searching-algorithm/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ <h2>Searching Algorithm Visualizer</h2>
103103
<hr />
104104
</div>
105105
</div>
106-
<div class="container foundNotice"></div>
106+
<div id="foundNotice" class="container text-success text-center"></div>
107107

108108
<footer>
109109
<div class="footer-text">

0 commit comments

Comments
 (0)