64,654
社区成员
发帖
与我相关
我的任务
分享
class Buddy{
public:
Buddy(){
x =0.0,y = 0.0;
}
Buddy(double newX, double newY) {
x = newX;
y = newY;
}
void setY(double newY) {
y = newY;
}
void setX(double newX) {
x = newX;
}
double getX() {
return x;
}
double getY() {
return y;
}
private:
double x;
double y;
};
Buddy* getMinDist(LinkedList<Buddy> *linkedlist){
Buddy *minDist = new Buddy();
Note<Buddy> *tempNode = linkedlist->getHeader()->next;
minDist->setX(tempNode->nodeValue.getX());
minDist->setY(tempNode->nodeValue.getY());
while(tempNode->next != linkedlist->getHeader()){
Note<Buddy> *newNode = tempNode->next;
if(newNode->nodeValue.getY() < minDist->getY()){
minDist->setX(newNode->nodeValue.getX());
minDist->setY(newNode->nodeValue.getY());
}
tempNode = tempNode->next;
}
if(debug)
cout<<"-----取回链表中的最小距离-----"<<endl;
return minDist;
}
int main(){
Budyy *newBuddy = getMinDist(LinkedList<Buddy> *list);
...
delete newBuddy;//Correct or not here
return;
}
int main(){
Budyy *newBuddy = getMinDist(LinkedList<Buddy> *list);
...
//delete newBuddy;//Correct or not here
newBuddy =NULL;//这样写呢?释放内存了吗
return;
}
static Buddy *minDist = new Buddy();
int main(){
Budyy newBuddy = getMinDist(LinkedList<Buddy> *list);//这里是使用一个对象来接收返回值了
...
delete newBuddy;//Correct or not here
return;
}