html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!-- Created by Shamironi -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
<title>Sorting Methods Showcase</title>
<link rel="stylesheet" href="styles.css">
<script defer src="scripts.js"></script>
</head>
<body>
<h1>Sorting Algorithim Options</h1>
<div class="btn-container">
<button id="selectionSort">Selection Sort</button>
<button>Bubble Sort</button>
<button>Insertion Sort</button>
</div>
</body>
</html>
css
css
1
2
3
4
5
6
7
/* Created by Shamironi */
.btn-container {
display: flex;
gap: 10px;
align-items: center;
}
js
js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Shamironi
window.addEventListener('load', checkJSLoaded)
function checkJSLoaded() {
// Selection Sort
function selectionSort(arr) {
if (arr.length === 0) {
return "empty";
}
let n = arr.length;
for (let i = 0; i < n - 1; i++) {
let min_indx = i;
for (let j = i + 1; j < n; j++) {
if (!isNaN(arr[j]) && !isNaN(arr[min_indx])) {
if (Number(arr[j]) < Number(arr[min_indx])) {
min_indx = j;
}
} else {
if (String(arr[j]).localeCompare(String(arr[min_indx])) < 0) {
min_indx = j;
}
}
}
let temp = arr[i];
arr[i] = arr[min_indx];
BROWSER
Console
Run