Problem 80b

Convert from a graph from adjacency-list to graph-term 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'])
    ]

graph80 == adjListToGraph adjList80

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))


adjListToGraph : AdjList comparable -> Graph comparable
adjListToGraph (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)
      [ graph80 == adjListToGraph adjList80
      , ([], []) == adjListToGraph []
      ]


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'])
    ]

Solution

Solution

results matching ""

    No results matching ""