-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble_sort.html
More file actions
29 lines (29 loc) · 845 Bytes
/
bubble_sort.html
File metadata and controls
29 lines (29 loc) · 845 Bytes
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
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Bubble Sort</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var arr = new Array(7, 1, 3, 5, 9, 4, 10, 6, 2);
var i, j, temp;
document.write("Before Bubble Sort<br>Array : [", arr, "]");
for (i = 0; i < arr.length; i++) {
for (j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
document.write(
"<br><br><b>After Bubble Sort<br>Array : <b><i>[",
arr,
"]</i>"
);
</script>
</body>
</html>