这是一个球无向图最短路径的代码,所有路径圈值都为1
点二行代码
#define POINT_COUNT_MAX 7
改成#define POINT_COUNT_MAX 8
运行就会崩溃,不知道为什么,个人猜测可能是递归调用的太多
求解答
#include<stdio.h>
#define POINT_COUNT_MAX 7
#define END_INDEX 17
int flag = 1;
int allPath[100][POINT_COUNT_MAX];
int pathNum = 0;
typedef struct POINT
{
int pathCount;
int path[20];
}POINT;
void fun(POINT *point, int index, int *pointCount);
void fun(POINT *point, int index, int *pointCount)
{
int i = 0;
int temp;
allPath[pathNum][(*pointCount)-1] = index;
if(*pointCount >= POINT_COUNT_MAX || index == END_INDEX)
{
if(index == END_INDEX)
{
pathNum++;
for(temp = 0; temp < POINT_COUNT_MAX; temp++)
allPath[pathNum][temp] = allPath[pathNum-1][temp];
}
}else{
for(i = 0; i < point[index].pathCount; i++)
{
*pointCount = *pointCount + 1;
fun(point, *(point[index].path + i), pointCount);
*pointCount = *pointCount - 1;
}
}
}
void main(void)
{
int pointCount = 1;
int i, j;
POINT point[18] =
{
/*0*/ {3,1,2,3},
/*1*/ {3,2,4,9,},
/*2*/ {4,1,3,4,5},
/*3*/ {4,2,5,6,7},
/*4*/ {5,1,2,5,8,9},
/*5*/ {7,2,3,4,6,9,10,12},
/*6*/ {7,3,5,7,8,12,13,14},
/*7*/ {3,3,6,8},
/*8*/ {4,6,7,14,15},
/*9*/ {5,1,4,5,10,11},
/*10*/ {4,5,9,11,12},
/*11*/ {3,9,10,16},
/*12*/ {5,5,6,10,13,16},
/*13*/ {6,6,12,14,15,16,END_INDEX},
/*14*/ {4,6,8,13,15},
/*15*/ {4,8,13,14,END_INDEX},
/*16*/ {4,11,12,13,END_INDEX},
/*17*/ {0,0}
};
fun(point, 0, &pointCount);
for(i = 0; i < pathNum; i++)
{
for(j = 0; j < POINT_COUNT_MAX; j++)
printf("%d", allPath[i][j]);
printf("\n");
}
}