Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-advanced-reader.ss" "lang")((modname |29.3|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;A graph is a (vectorof (listof nodes)).
6 ;neighbors : node graph -> (listof nodes)
7 ;Return the neighbors of anode given agraph.
9 (define (neighbors anode agraph)
10 (vector-ref agraph anode))
13 (define G (vector '(1 4)
14 '(4 5)
15 '(3)
16 empty
17 '(2 5)
18 '(3 6)
19 empty))
21 ;find-route : node node graph -> (listof nodes)
22 ;Find a route from ori to dest given G and return the route as a (listof nodes).
24 (define (find-route ori dest G)
25 (cond
26 [(= ori dest) (list ori)]
27 [else (local ((define possible-route (find-route/list (neighbors ori G) dest G)))
28 (cond [(boolean? possible-route) false]
29 [else (cons ori possible-route)]))]))
31 ;find-route/list : (listof nodes) node graph -> (listof nodes)
32 ;Find a route from lo-ori (listof nodes) to dest given G and return the route as a (listof nodes).
34 (define (find-route/list lo-ori dest G)
35 (cond
36 [(empty? lo-ori) false]
37 [else (local ((define possible-route (find-route (first lo-ori) dest G)))
38 (cond
39 [(boolean? possible-route) (find-route/list (rest lo-ori) dest G)]
40 [else possible-route]))]))