void Graph::setWeight (int *oldMatrix[], int vertices)
{
for (int i=0 ; i< vertices ; i++) {
for (int j=i+1 ; j<vertices ; j++) {
int z = 0;
for (int k=j+1 ; k<vertices ; k++)
{
int* ind1 = oldMatrix[i]; cout << oldMatrix[i] << "array";
int* ind2 = oldMatrix[j];
int* ind3 = oldMatrix[k];
bool match = compare (ind1, ind2, ind3);
if (match) z++;
}
matrix[i][j] = z; // set the new weight value
// cout << matrix[i][j] << endl;
cout << "e";
}
}
}
当我尝试遍历它们时,ind1,ind2和ind3不会产生结果。 oldMatrix在.h文件中声明为:
int ** matrix; // referred to as oldMatrix in graph class
setWeight被称为:
setWeight (oldMatrix, vertices); // vertices just an int
我试图打印出ind1,ind2和ind3的值,因为它们没有打印任何东西,但没有打印出来。
bool Graph::compare (int* ind1, int* ind2 , int* ind3)
{
int count = 0; cout << "s" << endl;
for (int i=0; i<BUFFER ; i++)
cout << ind1[i] << ind2[i] << ind3[i] << endl;
for (int i=0 ; i< vertices ; i++)
{
if (i%2 == 0){
if (ind1[i] == ind2[i] || ind2[i]== ind3[i] || ind1[i]==ind3[i]) // vertical i
count++;
if (ind1[i+1]== ind2[i+1] || ind2[i+1]==ind3[i+1] || ind1[i+1]==ind3[i+1]) // vertical i+1
count++;
if (ind1[i]== ind2[i+1] || ind1[i]==ind3[i+1] || ind1[i+1]==ind2[i] || ind1[i+1]==ind3[i]) // diagonal ind1
count++;
if (ind2[i]== ind1[i+1] || ind2[i]==ind3[i+1] || ind2[i+1]==ind1[i] || ind2[i+1]==ind3[i]) // diagonal ind2
count++;
if (ind3[i]== ind1[i+1] || ind3[i]==ind2[i+1] || ind3[i+1]==ind1[i] || ind2[i+1]==ind3[i]) // diagonal ind3
count++;
}
}
if (count >= 1)
return true;
else
return false;
}
有人可以提供一些建议吗?