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很好的实现将是非常相似 –