;; The first three lines of this file were inserted by DrRacket. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-advanced-reader.ss" "lang")((modname week8_w_full) (read-case-sensitive #t) (teachpacks ((lib "image.ss" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "image.ss" "teachpack" "2htdp"))))) (define-struct graph (nodes neighbor)) (define (add-edge g a b) (make-graph (graph-nodes g) (lambda (node) (append ((graph-neighbor g) node) (cond [(symbol=? node a) (list b)] [else empty]))))) (define mygraph (make-graph '(a b c d e f g) (lambda (node) (cond [(symbol=? node 'a) '(b)] [(symbol=? node 'b) '(d e)] [(symbol=? node 'c) '(e f)] [(member node '(d e f)) '(g)] [(symbol=? node 'g) '()]))) ) (check-expect ((graph-neighbor (add-edge mygraph 'c 'd)) 'c) '(e f d)) (check-expect ((graph-neighbor (add-edge mygraph 'c 'd)) 'b) '(d e))