变量没有按要求存储
Variable not storing as requested
下面是我的代码:
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;
}
由于一些奇怪的原因当我将i
存储在pointsToCalculate[i].originalLocation = i;
行时,它总是存储为0。我在它上面运行了断点,它显示i
的值在while循环中增加了,但它仍然将originalLocation
存储为0。当我在运行时检查值时,显示pointsToCalculate[i] is
1 or
2 , depends on how many times I have ran through the loop and it also shows that
= I中的i
;is also
1 or
2 '取决于循环。
谢谢,布兰登
如果distance <= threshold_distance
, i
不会增加,while循环将永远循环
相关文章:
- 存储变量的更有效方法是什么?
- 使用 system() 不存储变量C++?
- 在递归DP中,通过存储变量来分解递归调用:效率低下
- 使用 LDAP 存储C++变量
- 在满足特定条件时运行迭代C++以存储变量
- 使用getline解析和存储变量
- 如何存储变量的地址并使用指针打印值
- C++ / Objective-C++ - 如何在 NSDictionary 中存储C++变量?
- 如何从文件中读取并存储变量
- 指针是否延长了自动存储变量的生存期
- 如何在 INI、CFG 或 XML 文件中存储C++变量
- 如何在 c++ 中的字符串数组中存储变量
- 如何在特定偏移量处存储变量
- 如何存储变量的前一个值并更新它以进行比较
- 存储变量的有效方法是什么?(自制虚拟机)
- 在C++中存储变量
- 在c++中按值调用时,存储变量的副本
- 为什么lambda只捕获自动存储变量
- 如何在寄存器中存储c++变量
- Getline()结合cin.ignore()不存储变量?(错误)