运行结果正确
非递归虽然实现起来比较复杂,但是容易纠错,也更好理解
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include<malloc.h>
//创建邻接表
//这个边的数据结构是用来给我们输入使用的
typedef struct se_node *se_point;
struct se_node{
int v1,v2;
int weight;
} ;
//创建邻接表的边
typedef struct e_node *e_point;
struct e_node{
int indx;
int weight;
e_point next;
};
//创建邻接表的顶点
typedef struct v_node *v_point;
struct v_node{
e_point first_edge;
int date;
};
//创建邻接表的图
typedef struct g_node *g_point;
struct g_node{
int v_num;
int e_num;
struct v_node list[100];
};
//遍历这个图
void tra_adj(g_point g,int num){
printf("邻接表遍历结果\n");
for(int i=0;i<num;i++){
printf("%d ",i);
e_point e=g->list[i].first_edge;
for(;e!=NULL;e=e->next){
printf("%d ",e->indx);
}
printf("\n");
}
}
//初始化图
void init_adj(