Need some help with DrScheme... create nested lists
Here what I am trying to do.... Write the function partialpaths, of two arguments. The first argument is a list of lists, representing a graph(adjacency list representation of a graph). The second argument is a partial path in the reverse order, for example the path "from a to b to c" is represented by the list (c b a). The function should return a list of sublists containing all possible expansions of this partial path by one node. For example: (partialpaths '( (a b c) (b c d) (c d a) (d)) '(b a)) should return: ( (c b a) (d b a)) Here's what I got: I get (b c d) to show up and now I have to attach each element but the first onto the second one to create a list of lists. Here's my code: (define nod ()) (define ma '('())) (define (partialpaths L1 L2) (set! nod (equal L1 L2)) (do() ;exit test ((null? (cdr nod))) (list (list attach(cdr nod) L2) ma) (set! nod (cdr nod)) ) ma ) (define (attach List1 List2) (list (car List1) List2) ) (define (equal L1 L2) (cond ((eq? (caar L1) (car L2)) (car L1)) (else (equal (cdr L1) L2)) ) )
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement