-3
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;
}
}
請妥善編輯。我們很難讀。 – KRUKUSA