gpt4 book ai didi

c++ - 变量未按要求存储

转载 作者:太空宇宙 更新时间:2023-11-04 12:17:13 24 4
gpt4 key购买 nike

这是我的代码:

point * findLongPaths(point * points, double threshold_distance) {
unsigned int i = 0;
int locationToStore = 0;
int pointsAboveThreshold = countPointsAboveThreshold(points, threshold_distance);
//int totalPoint = totalPoints(points);

point * pointsByThreshold = new point[pointsAboveThreshold];
pointValues * pointsToCalculate = new pointValues[pointsAboveThreshold];
//pointValues pointsToCalculate[pointsAboveThreshold];
//point orderedPoints[pointsAboveThreshold];

while (points[i].end != true && i < pointsAboveThreshold) {
point pointOne = points[i];
point pointTwo = points[i + 1];

//Check to see if the distance is greater than the threshold, if it is store in an array of pointValues
double distance = distanceBetweenTwoPoints(pointOne, pointTwo);
if (distance > threshold_distance) {
pointsToCalculate[i].originalLocation = i;
pointsToCalculate[i].distance = distance;
pointsToCalculate[i].final = pointTwo;
pointsToCalculate[i].stored = false;

//If the final point has been calculated, break the loop
if (pointTwo.end == true) {
pointsToCalculate[i].end = true;
break;
} else {
pointsToCalculate[i].end = false;
i++;
continue;
}
}
}

if (points[0].end == true && pointsAboveThreshold == 0) {
point emptyPoint;
emptyPoint.x = 0.0;
emptyPoint.y = 0.0;
emptyPoint.end = true;

pointsByThreshold[0] = emptyPoint;
return pointsByThreshold;
}

//Find the point with the lowest distance
i = 1;
//double lowest = 0.0;

//EDITED
pointValues pointWithLowest;
pointWithLowest = pointsToCalculate[0];
while (pointsToCalculate[i].end != true) {
for (int j = 0; pointsToCalculate[j].end != true; j++) {
if (pointsToCalculate[j].stored == true) {
j++;
continue;
} else {
if (pointsToCalculate[j].distance < pointWithLowest.distance) {
pointWithLowest = pointsToCalculate[j];
j++;
continue;
} else if (pointsToCalculate[j].distance == pointWithLowest.distance) {
if (pointWithLowest.originalLocation > pointsToCalculate[j].originalLocation) {
pointWithLowest = pointsToCalculate[j];
j++;
continue;
}
} else {
pointWithLowest.stored = true;
pointsByThreshold[locationToStore] = pointWithLowest.final;
locationToStore++;
break;
}
}
}
i++;
}
delete[] pointsToCalculate;
return pointsByThreshold;
}

由于某些奇怪的原因,当我在 pointsToCalculate[i].originalLocation = i; 行中存储 i 时,它总是存储为 0。我运行了断点在它上面,它显示 i 的值在 while 循环中递增,但它仍在将 originalLocation 存储为 0。当我在运行时检查值时,它显示pointsToCalculate[i] 中的 i12,这取决于我在循环中运行了多少次,它还显示那= i;也是12`,这取决于循环。

有人知道这是为什么吗?这是一项几个小时后到期的作业,我已经为此工作了很长时间。还是想不通。

谢谢,布兰登

最佳答案

如果distance <= threshold_distance ,i不会递增,while循环会一直循环

关于c++ - 变量未按要求存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7135949/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com