这是小白自己写的,可能里边优化不行,但是能运行的。
其中变量的在函数间的传递一直是我的迷茫点,二维数组的传递更是没有用过,经过一天的摸索,才发现是自己想的太复杂了。。
下边是代码:
#include<iostream>
#include<ctime>
#define NUM 4
static int temp_end = -1, temp_head = -1;
static int n=0;
int Find(int c_1[][NUM],int end_1)//寻找
{
for (int i = 0; i < NUM; i++)
{
if (c_1[end_1][i] == 1)
{
std::cout << n << "\n";
n++;
c_1[end_1][i] = -1;
temp_end = end_1;
temp_head = i;
Find(c_1, i);
}
}
if (temp_end == -1 && end_1 < (NUM-1))
Find(c_1, ++end_1);
return 0;
}
void FindDrive(int c[][NUM])//驱动
{
int end = 0;
Find(c,end);
}
int main()
{
int c_relation[4][4];
for (int i = 0; i < NUM; i++)
for (int j = 0; j < NUM; j++)
c_relation[i][j] = 0;
c_relation[0][1] = 1;
c_relation[0][2] = 1;
c_relation[1][3] = 1;
c_relation[2][1] = 1;
c_relation[3][1] = 1;
c_relation[3][2] = 1;
FindDrive(c_relation);
for (int i = 0; i < NUM; i++)
{
for (int j = 0; j < NUM; j++)
std::cout << c_relation[i][j] << " ";
std::cout << "\n";
}
}