title | date | draft | tags | categories | |||
---|---|---|---|---|---|---|---|
Algorithm4 Java Solution 4.1.04 |
2020-01-28 06:59:15 +0800 |
false |
|
|
4.1.4 Add a method hasEdge() to Graph which takes two int arguments v and w and returns true if the graph has an edge v-w, false otherwise.
code:
public static void main(String[] args) {
Ex_4_1_04 e = new Ex_4_1_04();
_Graph g = new _Graph(new In("algdata/tinyGex2.txt"));
PrintUtil.printSepLine("original");
StdOut.println(g);
int v = 2, w = 3;
e._showHasEdge(g, v, w);
v = 2;
w = 9;
e._showHasEdge(g, v, w);
// 2-3 true
// 2-9 false
}
private void _showHasEdge(_Graph g, int v, int w) {
StdOut.printf("%d-%d %s\n", v, w, g.hasEdge(v, w));
}