Create a method named isUndirected
.
isUndirected
accepts an UnweightedGraph<*>
from cs1.graphs
and should return true
if the graph is
undirected and false
otherwise.
Each node in the graph has a set of neighbors that you can retrieve representing links from that node to other nodes. If the graph is undirected, if there is a link from A to B then there is also a link from B to A. So if B is a neighbor of A, then A should also be a neighbor of B.
Note that you do not need to solve this problem recursively, since there is a concise iterative solution.
For reference, cs1.graphs.UnweightedGraph
is declared somewhat like this:
And cs1.graphs.GraphNode
is declared somewhat like this:
You're challenge is to write tests for this problem described above.
Stuck? You may find these lessons helpful: