You have N computers and [Ca, Cb] means a is connected to b and this connectivity is symmetric and transitive. then write a program which checks that all computers are interconnected and talk two each other
char array[n][n] = {0};
for all point [ca,cb]
array[ca][cb]=1
tmpQ=emty;
tmpQ.enque(1);
ConnectedNode[N]=0;
ConnectedNode[1]=1;
while(!tmpQ.empty)
{
int node=tmpQ.dequque();
for(int i=0;i<n;i++)
if( array[node][i]==1)
{
ConnectedNode[i]=1;
tmpQ.enque(i);
}
}
for(int i=0;i<n;i++)
if( ConnectedNode[i] == 0)
return false;
return true;
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks