1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| #include <stdio.h>
class Node
{
public:
Node(int x=0,int y=0,int z=0,int cost=0, Node *parent=NULL);
~Node();
void SetAll(int x,int y,int z,int cost,Node *parent);
void SetAll(Node *n);
void SetX(int x){m_x = x;}
int GetX(){return m_x;}
void SetY(int y){m_y = y;}
int GetY(){return m_y;}
void SetZ(int z){m_z = z;}
int GetZ(){return m_z;}
void SetCost(int cost){m_cost = cost;}
int GetCost(){return m_cost;}
void SetParent(Node *parent){m_parent = parent;}
Node *GetParent(){return m_parent;}
void Print();
private:
int m_x; // position x
int m_y; // position y
int m_z; // position z (non utilisé pour le moment)
int m_cost; // coût individuel
Node *m_parent;
};
Node::Node(int x,int y,int z,int cost,Node *parent)
{
SetAll(x,y,z,cost,parent);
}
Node::~Node()
{
}
void Node::SetAll(Node *n)
{
m_x = n->GetX();
m_y = n->GetY();
m_z = n->GetZ();
m_parent = n->GetParent();
}
void Node::SetAll(int x,int y,int z,int cost,Node *parent)
{
m_x = x;
m_y = y;
m_z = z;
m_cost = cost;
m_parent = parent;
}
void Node::Print()
{
int px=0,py=0;
if(m_parent!=NULL)
{
px = m_parent->GetX();
py = m_parent->GetY();
}
printf("x=%d y=%d cost=%d xparent=%d yparent=%d\n",m_x,m_y,m_cost,px,py);
} |
Partager