-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbestwayhome.bas
53 lines (53 loc) · 1.11 KB
/
bestwayhome.bas
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
10 REM QUICKEST WAY HOME: DEMONSTRATE ALGORITHM ONLY
20 REM (DATA NOT CHECKED FOR ABSURDITIES)
30 REM ALLOW FOR 50 NODES AND 120 EDGES
40 DIM A(50,4), B(120,3)
50 PRINT "NO.OF NODES, NO.OF EDGES, START NODE, HOME NODE"
60 INPUT N, E, S, H
70 FOR I=1 TO N
80 LET A(I,1) = 1
90 LET A(I,2) = 1000000
100 LET A(I,3) = 0
110 LET A(L,4) = 0
120 NEXT I
130 LET A(S,2)=0
140 REM INPUT AND LINK (NO CHECKS ON INPUT DATA)
150 PRINT "A--->---B, EDGE-TIME"
160 FOR P=1 TO E
170 INPUT A, B, R
180 LET B(P,2) = B
190 LET B(P,3) = R
200 LET B(P,1) = A(A, 4)
210 LET A(A,4) = P
220 NEXT P
230 LET I=S
240 GO TO 320
250 LET I=L+4
260 IF I<=N THEN 300
280 LET K=K+1
290 IF K>1 THEN 440
300 REM
310 IF A(I,1) = 0 THEN 250
320 LET J=A(I,4)
325 IF J=0 THEN 420
330 LET K=0
340 LET T=A(I,2) + B(J,3)
350 LET L=B(J,2)
360 IF A(L,2)<T THEN 400
370 LET A(L,1)=1
380 LET A(L,2)=T
390 LET A(L,3)=I
400 LET J=B(J,1)
410 IF J<>0 THEN 340
420 LET A(I,1)=0
430 GO TO 250
440 REM PRINT RESULT
450 PRINT "QUICKEST WAY FROM";S;"TO";H;"TAKES";A(H,2);"THRU"
460 PRINT H;
410 LET X=A(H,3)
480 IF X=0 THEN 520
490 PRINT X;
500 LET X=A(X,3)
510 GO TO 480
520 PRINT
530 END