1.设计一个坐标类:
class mazepoint
{
friend class mazestack;
public:
mazepoint(){}
mazepoint(int a, int b)
{
x = a;
y = b;
}
~mazepoint(){}
private:
int x;
int y;
mazepoint* next;
};
2.设计一个堆栈,存储坐标点:
//定义一个栈,可以将坐标放进栈中
class mazestack
{
public:
mazestack()
{
length = 0;
top = NULL;
}
~mazestack(){}
void push(const mazepoint* item)
{
if (top == NULL)
{
mazepoint* newnode = new mazepoint;
newnode->x = item->x;
newnode->y = item->y;
newnode->next = NULL;
top = newnode;
++length;
}
else
{
mazepoint* newnode = new mazepoint;
newnode->x = item->x;
newnode->y = item->y;
newnode->next = top;
top = newnode;
++length;
}
}
void pop()
{
if (top == NULL)
{
cout <<