X1592: Complete method hasEdge

Description

Define a method boolean hasEdgeFromAToB(Graph g, int a, int b) that returns true if there is an edge from a to b. The object g contains an undirected graph of type Graph. Graph implements the GraphADT interface (partially shown below); you must use the methods of GraphADT to access the information necessary to answer this question.

Reference

  • The documentation for the GraphADT interface is available online.
  • We have included a partial definition of Graph here for your convenience.

    public class Graph implements GraphADT<String> ...
    {
    // Is this graph a directed graph?
    public boolean isDirected() {...}
    
    // Return the number of nodes in this graph
    public int getNodeCount() {...}
    
    // Return the number of edges in the graph.
    public int getEdgeCount() {...}
    
    // Returns true iff the graph has the edge
    // from v to w.
    public boolean hasEdge(int v, int w) {...}
    
    // Return the number of edges on node v.
    public int getNodeDegree(int v) {...}
    }
    

Your Answer:

Feedback

Your feedback will appear here when you check your answer.