-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample1.html
37 lines (32 loc) · 1.11 KB
/
example1.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
<!--
JS returns the array of shortest lengths form start node to others
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dijkstra Example</title>
<script src = "Dijkstra.js"></script>
</head>
<body>
<script>
var array = [
[Number.POSITIVE_INFINITY, 9, 4, 7, 12, 26, 34],
[2, Number.POSITIVE_INFINITY, 23, 22, 45, 2, 45],
[77, 23, Number.POSITIVE_INFINITY, 34, 34, 1, 22],
[11, 23, 61, Number.POSITIVE_INFINITY, 12, 38, 5],
[61, 11, 36, 82, Number.POSITIVE_INFINITY, 25, 62],
[44, 27, 77, 23, 22, Number.POSITIVE_INFINITY, 19],
[31, 6, 7, 78, 23, 55, Number.POSITIVE_INFINITY]
];
//1 arg - array, second - source node, third - false, if we dont want to see the trace, true - if we want
console.log("Lengths from 0-node to others:");
var deikstra = new Dijkstra(array, 0, false);
console.log(deikstra);
//If we want to know the length of shortest path between 2 nodes we can simply refer the index of second node:
console.log("Length from 0-node to first node:");
deikstra = new Dijkstra(array, 0, false)[1];
console.log(deikstra);
</script>
</body>
</html>