我正在编写的一些代码有问题。我经常使用这个网站,因为我发现很多人已经问过我想知道的相同问题。借此,我要感谢这里的社区,感谢他们之前对我的编程难题的所有见解。(在我们走得太远之前,不,这不是“学校项目”或“学校作业”,我只是想解决“旅行推销员问题”并提高我的 C 技能。
这是我一直坚持的代码部分:
void printAndFlip(int arrayone[][20], int citytotal, int arrayCities[])
{
////Finds cost:
int x, y, z;
int totalCost
int singleTrip;
int cheepestTrip;
int nCity = citytotal + 1; //nCity is the number of Cities //Adding one to accomadate going back to the first city
int gCounter;
int gCounterTrue = 1;
int cheepestTrip[20];
int totalCost = 0;
int lCounter;
int i;
int n = citytotal;
////Sets up for a default case to set cheepestTrip:
for(gCounter = 1; gCounter <= nCity; gCounter++)
{
while(gCounterTrue == 1)
{
if(gCounter == arrayCities[gCounter])
{
gCounterTrue = 1;
}
else
{
gCounterTrue = 0;
gCounter = 50; //Stopping the larger for loop with 50 (the nCity can't be larger than 20) so that it will hopefully be faster
}
if(gCounter == nCity)
{
if(arrayCities[1] == arrayCities[nCity])
{
!!!!! cheepestTrip = totalCost;
}
}
}
}
for(x = 1; x < nCity; x++)
{
y = arrayCities[x];
z = arrayCities[x+1];
singleTrip = arrayone[y][z]; //finding individual cost of each trip...will be added to 'totalCost' below
totalCost = singleTrip + totalCost;
}
!!!!!!!! if(totalCost <= cheepestTrip)
{
for(lCounter = 1; lCounter <= nCity; lCounter++)
{
cheepestTrip[lCounter] = arrayCities[lCounter];
}
}
为了更容易显示我的编译错误在哪里,我在行上加上了感叹号。如果我错了,请告诉我,但是当我将“arrayone”发送到 printANDFlip 时,我正在传递一个带有数组的指针数组,对吗?我知道编译错误与指针有关,但我不确定它们应该放在哪里。任何和所有的帮助将不胜感激。非常感谢,亚历克斯