#include<iostream>
using namespace std;
class Maze
{
struct intersection
{
int left;
int forward;
int right;
}* dir;
int crossing;
int exit;
public:
Maze(int x):crossing(x)
{
dir=new intersection[x+1];
}
friend istream& operator>>(istream& in,Maze m);
void setExit(int x)
{
exit=x;
}
int visit(int x) //只能搜索一条路径
{
if(x>0)
{
if(x==exit)
{
cout<<"postion :"<<x<<endl;
return 1;
}
if(visit(dir[x].left))
{
cout<<"postion :"<<x<<endl;
return 1;
}
if(visit(dir[x].forward))
{
cout<<"postion :"<<x<<endl;
return 1;
}
if(visit(dir[x].right))
{
cout<<"postion :"<<x<<endl;
return 1;
}
}
return 0;
}
};
istream& operator>>(istream& in,Maze m)
{
for(int i=1;i<=m.crossing;i++)
cin>>m.dir[i].left>>m.dir[i].forward>>m.dir[i].right;
return in;
}
int main()
{
int i;
cout<<"input Maze's scale:";
cin>>i;
Maze fancy(i);
cout<<"input values:";
cin>>fancy;
cout<<"input the exit:";
cin>>i;
fancy.setExit(i);
cout<<"input the beginning visit place:";
cin>>i;
fancy.visit(i);
return 0;
}
//input Maze's scale:
//6
//input values:
//0 2 0
//3 5 6
//0 0 4
//0 0 0
//0 0 7
//7 0 0
//input the exit:7
//input the beginning visit place:1
//postion :7
//postion :5
//postion :2
//postion :1
|