include <stdio.h>
int check(int grid[12][12],int row);
int find_route(int grid[12][12],int row,int sum);
int main()
{
int sum=0;
int subway[12][12]={
{0,1,0,0,0,0,0,0,0,0,0,0},
{1,0,1,1,1,1,0,0,0,0,0,0},
{0,1,0,0,1,0,0,0,0,0,0,0},
{0,1,0,0,1,0,0,0,0,0,0,0},
{0,1,1,1,0,0,1,1,0,0,0,0},
{0,1,0,0,0,0,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,1,0},
{0,0,0,0,1,1,0,0,1,1,1,0},
{0,0,0,0,0,0,0,1,0,0,1,0},
{0,0,0,0,0,0,0,1,0,0,1,0},
{0,0,0,0,0,0,1,1,1,1,0,1},
{0,0,0,0,0,0,0,0,0,0,0,0},
};
find_route(subway,0,sum);
printf("%d",sum);
};//main
int check(int grid[12][12],int row){
int i;
for (i=0;i<12;i++){
if (grid[i][row]==1){
return i;
}//if statement
else if (i==11){
return 12;
}// else if
};//for loop
};//check
int find_route(int grid[12][12],int row, int sum){
int col= check(grid,row);
printf("position is %d %d\n",row,col);
if (row==11){
sum++;
}
//find the path and prit out everthing
else if (col==12){
return 0;
//dead end
}
else{
grid[row][col]=0;
grid[col][row]=0;
find_route(grid,col,sum);
}
};
大家我又回来了,,我大概写出了一些,,不过我的只能找出一条路,按道理应该有上百种呢,我试着printf我的路径发现,只走了一条,我感觉,我应该再最后的else那,把我已经改过的0变回1,但是我不知道应该怎么放?而且那个recursion function findroute 应该再多重复召唤几次,可是我应该改些什么才能重复召唤呢?我应该怎么寸我的char,然后printf出用字母表示的路径呢?谢谢大神们