图形定义如下:[("1",["2","3"]),("2",["1"]),("3",["1"])]
我想写一个广度优先搜索。
这是我的代码:
search_command graph start ""=(graph,"You didnt enter start vertex!\n")
search_command graph "" end=(graph,"You didnt enter end vertex!\n")
search_command graph start end=
if (has_element graph start)&&(has_element graph end) then
(graph,unwords (search graph [start] end [] []))
else if (has_element graph end)==False then
(graph,"Element with "++end++" name not found!")
else
(graph,"Element with "++start++" name not found!")
search [] _ _ [] result=result
search (item:graph) (x:start) end use result=
if (fst item==x)&&(elem x use)==False then
search graph (get_connect_vertices graph graph (fst item) []) end (use++[x]) (result++[x])
else if (fst item==end)&&(fst item==x) then
search [] [] "" [] (result++[x]++[end])
else
search graph [x] end use (result)
但是当我运行它时,我得到了异常: 异常:D:\Workspace\Labwork2\src\Main.hs:(190,1)-(197,49): Non-exhaustive patterns in function search