What am I missing, My program won't give me any outputs. I am also getting an error "constructor class cannot applied given types" like that.
我们的教训是关于深度优先搜索和二进制图,但我错误地不上课,所以现在我后悔了。请有人帮助我。
我无法添加一些细节,因为我真的不知道这个程序是如何工作的,所以我真的很抱歉。
public class MainDriver{
public static void main(String[] args) {
Graph mygraph = new Graph(22);
mygraph.addEdge(1,2);
mygraph.addEdge(2,4);
mygraph.addEdge(2,5);
mygraph.addEdge(4,8);
mygraph.addEdge(4,9);
mygraph.addEdge(8,16);
mygraph.addEdge(8,17);
mygraph.addEdge(9,18);
mygraph.addEdge(9,19);
mygraph.addEdge(5,10);
mygraph.addEdge(5,11);
mygraph.addEdge(10,20);
mygraph.addEdge(10,21);
mygraph.addEdge(1,3);
mygraph.addEdge(3,6);
mygraph.addEdge(3,7);
mygraph.addEdge(6,12);
mygraph.addEdge(6,13);
mygraph.addEdge(7,14);
mygraph.addEdge(7,15);
}
DepthFirstSearch dfs = new DepthFirstSearch(G,v );
}
----------
Here's my subclass
public class DepthFirstSearch{
private boolean[] marked;
private int count;
public DepthFirstSearch(Graph G, int s) {
marked = new boolean[G.getV()];
dfs(G, s);
}
private void dfs(Graph G, int v) {
marked[v] = true;
System.out.print(v);
count++;
for (int w : G.adj(v)) {
if (!marked[w]) {
dfs(G, w);
}
}
}
public boolean marked(int w) {
return marked[w];
}
public int count() {
return count;
}
}
答案 0 :(得分:0)
您的程序不会输出任何内容,因为您的代码不会输出任何内容。
我只能假设你应该实施自己的" Printing"或"绘图"功能。
如果你想在输出上看到某些东西(任何东西),就这样做:
public static void main(String[] args) {
System.out.println("START");
Graph mygraph = new Graph(22);
mygraph.addEdge(1,2);
...
mygraph.addEdge(7,15);
System.out.println("END");
}
你应该得到输出:
START
END