可能是像(不是很強大/彈性和未測試),只是想知道如何做到這一點。
我認爲該文件是格式
0: [2,3,4]
1: [2,4,6]
etc
Java代碼:
FileInputStream fis = new FileInputStream(fin);
//Construct BufferedReader from InputStreamReader
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = null;
while ((line = br.readLine()) != null) {
int vertex = Integer.parseInt(line.substring(0, line.indexOf(":")) //get the number before :
String neighboorString = (line.substring(line.indexOf("[")+1, line.indexOf("]") //get the string between [ ]
List<Integer> neighbors = new ArrayList<Integer>();
for (String neighbor : neighborString.split(",")) { //split the string between , to get the neighbor id
neighbors.add(Integer.parseInt(neighbor))
}
//populate your structure as required)
}
//close the streams/readers
非常感謝你的代碼非常有幫助 – etudiant 2014-12-03 17:16:35
請我想要的顏色此圖有5種顏色爲了這個,我問2條件,但我不知道我是如何在Java的初學者幫助我 - 如果一個圖的頂點有4個鄰居,它可以使用其鄰居未使用的顏色對頂點進行着色 - 如果頂點可能有5個鄰居爲頂點着色顏色不被其鄰居使用 請如何閱讀該文件,因爲我在頁面頂部指示要應用顏色條件,返回每種顏色的頂點列表請幫助我 – etudiant 2014-12-05 22:47:58