注册 登录
编程论坛 C++ Builder

高手们帮我看看问题出在哪,运行的结果不正确啊!(迷宫问题)谢谢啦!

yfvictory 发布于 2011-05-16 09:26, 1265 次点击
#include<iostream>
using namespace std;
#define Empty  0
struct Node
{
    int style;
    Node *next;
};

class Stack
{
    Node *head;
public:
    Stack();
    int Pop();
    void Push();
    bool isNull();
   
};
Stack::Stack()
{
    head=NULL;
}

int Stack::Pop()
{
    Node *Node_temp;
    while(head)
    {
        Node_temp=head;
        head=head->next;
        delete Node_temp;
    }
    return 0;
}

void Stack::Push()
{
    char n[6];
    Node *Node_temp=new Node;
    Node_temp->style=n[6];
    Node_temp->next=head;
    head=Node_temp;
}

bool Stack::isNull()
{
    if(head)
        return true;
    return false;
}



void main()
{
    int A[6][8]={{1,1,1,1,1,1,1,1},{1,0,0,1,0,0,1,1},{1,1,0,0,0,0,0,1},{1,0,0,1,0,1,0,1},{1,0,0,0,0,0,0,1},{1,1,1,1,1,1,1,1}};
    int move[4];
    int x,y;
    int d=0;
    for(x=4;x>1;x--)
        for(y=6;y>1;y--)
        {
            Stack   s;
            if(d=0)
                move[d]=A[x][y+1];
            if(d=1)
                move[d]=A[x+1][y];
            if(d=2)
                move[d]=A[x][y-1];
            if(d=3)
                move[d]=A[x-1][y];
            if(move[d]=0)
            {

                 char  n[6]="x,y,d";
               
                s.Push();
            }
            if(move[d]=1)
            {
                if(d<4)
                d++;
                else
                    d=0;
            }
            if(x=1,y=1)
            {
                cout<<"有通路,通路路径如下:\n"<<s.Pop()<<'\n';
            }
            else
            {
                cout<<"没有通路"<<endl;
            }
        }
}





0 回复
1