-1
有人可以澄清這部分代碼如何將數據輸入到圖表上。 .data是什麼類型的文件?從.data文件讀取圖形
public class DepthFirst {
static int numNodes;
static GraphNode nodes[];
...........
...........
public static void readGraph() throws IOException {
File input = new File("digraph.data");
Scanner digraph = new Scanner(input).useDelimiter("\\D+");
//if file is not empty
if (digraph.hasNext()) {
int nodeNum;
numNodes = digraph.nextInt(); //System.out.println(numNodes);
nodes = new GraphNode[numNodes];
while (digraph.hasNext()) {
nodeNum = digraph.nextInt();
nodes[nodeNum] = new GraphNode(nodeNum, digraph.nextInt());
for (int i = 0; i < nodes[nodeNum].getDegree(); i++)
nodes[nodeNum].setAdjListIndex(digraph.nextInt(), i);
}
}
else return;
}
乾杯 工作