问题出现在下面的变量shortestval
中。它在下面被声明和初始化(在 1000 处)。
ENSEMBLE Cscan = *C;
ENSEMBLE Vscan = *V;
int departnumero = Vscan->numero, arrivenumero = Cscan->numero, departshortest, arriveshortest;
double shortestval = 1000;
LISTE aretescan = NULL;
int x=0, y=0, z=0;
while( (*C) != NULL && iteration < 100){
iteration++;
departshortest = 99;
arriveshortest = 99;
printf("\n\n shortestval = %i", shortestval); // Check 1
while(Vscan != NULL && x < 100){
printf("\n\n\t shortestval = %i", shortestval); // Check 2
while(Cscan != NULL && y < 100){
printf("\n\n\t\t shortestval = %i", shortestval);// Check 3
aretescan = aretes[Vscan->numero];
while(aretescan != NULL && z < 100){
printf("\n\n\t\t\t shortestval = %i", shortestval);// Check 4
if(aretescan->arrive == Cscan->numero){
if(aretescan->cout <= shortestval){
printf("\n \t\t\t (%d < %d)", aretescan->cout, shortestval);
shortestval = aretescan->cout;
departshortest = aretescan->depart;
arriveshortest = aretescan->arrive;
}
printf("\nD - %d \tA - %d \tC - %d", aretescan->depart, aretescan->arrive, aretescan->cout);
printf("\t\t\tD - %i, A - %i, C - %i", departshortest, arriveshortest, shortestval);
}
aretescan = aretescan->suiv;
z++;
}
Cscan = Cscan->voisin;
y++;
}
Vscan->voisin;
x++;
}
然而,// Check 1
紧接着,打印的值是“0”。这一直持续到while(aretescan != NULL && z < 100)
循环,其中行:
printf("\n \t\t\t (%d < %d)", aretescan->cout, shortestval);
shortestval
在行前打印 -858993460 为,
printf("\t\t\tD - %i, A - %i, C - %i", departshortest, arriveshortest, shortestval);
为 while 循环的第一次迭代打印一个值 5,这是我所期望的(这是设置的值aretescan->cout
)shortestval
。但反复地,if(aretescan->cout <= shortestval)
似乎反复将 shortestval 设为 = 858993460,或者在每次迭代时未能达到非常高的值,因为它根据依赖于 if 语句的操作重新分配自己,但到下一次迭代到来时围绕它继续被解读为这个神秘的价值。
我完全被难住了。任何想法将不胜感激。