-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.html
37 lines (33 loc) · 1016 Bytes
/
11.html
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
29
30
31
32
33
34
35
36
37
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Algorithm Example</title>
</head>
<body>
<h1>Algorithm Example</h1>
<script>
// Example algorithm: Bubble Sort
function bubbleSort(arr) {
let n = arr.length;
for (let i = 0; i < n - 1; i++) {
for (let j = 0; j < n - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
// Swap arr[j] and arr[j+1]
let temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
return arr;
}
// Example usage
let array = [64, 34, 25, 12, 22, 11, 90];
console.log("Unsorted array:", array);
let sortedArray = bubbleSort(array);
console.log("Sorted array:", sortedArray);
</script>
</body>
</html>