0
我在完成關於BFS的代碼編寫之後,我正在學習圖形我的腦海裏有一個問題,我該如何改進我的代碼以使它也能檢查這個圖形是不是二分?使用相同的功能。 我要的顏色,代碼訪問這樣
INT顏色的節點; // - 1(無色未訪問節點),1(紅色爲母),0(藍色兒童)檢查圖形是否是雙向的
可能有人幫助我用它 :) ?
struct node {
int child_count;
int child[max];
int color;
};
void BFS(node*G[], int s){
int w, v;
queue <int> q;
bool visited[max];
for (int i = 0; i < s; i++){
visited[i] = false;
}
for (int i = 0; i < s; i++){
if (!visited[i])
q.push(i);
while (!q.empty())
{
v = q.front();
if (!visited[v])
{
visited[v] = true;
for (int i = 0; i < G[v]->child_count; i++)
{
w = G[v]->child[i];
q.push(w);
}
}
q.pop();
}
}
}
謝謝你,可是我沒學JAVA尚未;) – user4585412
@ user1597很好的實現將是非常相似 –