Problem 80a

Convert from a graph from graph-term to adjacency-list representation. (See Graphs for details on these formats.)

Example

graph80 = ( [ 'b', 'c', 'd', 'f', 'g', 'h', 'k' ],
            [ ('b','c'), ('b','f'), ('c','f'), ('f','k'), ('g','h') ] )

adjList80 = 
    [ ('b',['c','f'])
    , ('c',['b','f']) 
    , ('d',[])
    , ('f',['b','c','k']) 
    , ('g',['h'])
    , ('h',['g'])
    , ('k',['f'])
    ]

adjList80 == graphToAdjList graph80

Unit Test

import Html
import List
import Set


type alias Edge comparable = (comparable, comparable)
type alias AdjList comparable = (List((comparable, List comparable)))
type alias Graph comparable = (List comparable, List (Edge comparable))


graphToAdjList : Graph comparable -> AdjList comparable
graphToAdjList (nodes, edges) = 
    -- your implementation goes here
    []


main =
    Html.text
        (if (test) then
            "Your implementation passed all tests."
         else
            "Your implementation failed at least one test."
        )


test : Bool
test =
    List.all ((==) True)
      [ adjList80 == graphToAdjList graph80
      , [] == graphToAdjList ([], [])
      ]


graph80 = ( [ 'b', 'c', 'd', 'f', 'g', 'h', 'k' ],
            [ ('b','c'), ('b','f'), ('c','f'), ('f','k'), ('g','h') ] )


adjList80 = 
    [ ('b',['c','f'])
    , ('c',['b','f']) 
    , ('d',[])
    , ('f',['b','c','k']) 
    , ('g',['h'])
    , ('h',['g'])
    , ('k',['f'])
    ]

Hints

  1. Set.fromList and Set.toList may come in handy.

Solution

Solution

results matching ""

    No results matching ""