我在c ++中编写了一个不起作用的简单算法.我发现当我从我自己制作的自定义类中排序指向对象的列表时,它们会发生变化.或者更确切地说,列表更改为该类中的奇怪随机对象.
// ConsoleApplication45.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <map>
#include <list>
#include <math.h>
using namespace std;
class LocationNode;
class NodeMap;
class LocationNode
{
private:
char name;
int xLocation;
int yLocation;
//map<LocationNode*,int> neighbors;
LocationNode* neighbors[100];
int neighborWeight[100];
int neighborCount;
LocationNode *previous;
int score;
int CalcDistance(LocationNode &dest)
{
return (int)sqrt(pow(dest.xLocation-xLocation,2) + pow(dest.yLocation-yLocation,2));
}
public:
int finalScore;
bool operator<(LocationNode const& rhs) const
{
// Use whatever makes sense for your application.
return …Run Code Online (Sandbox Code Playgroud)