有人可以澄清这部分代码如何将数据输入到图表中。.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;
}
干杯工作