|
下面这段代码
//有向图的拓扑排序
#include <stdio.h>
#include <malloc.h>
#define MAXV 50
#define INF 32767
typedef int InfoType;
//邻接矩阵存储方法
typedef struct
{
int no;
InfoType info;
} VertexType;
typedef struct
{
int edges[MAXV][MAXV];
int n,e;
VertexType vexs[MAXV];
} MGraph;
//邻接表存储方法
typedef struct ANode
{
int adjvex;
struct ANode *nextarc;
InfoType info;
} ArcNode;
typedef struct
{
VertexType data;
int count;
ArcNode *firstarc;
} VNode;
typedef VNode AdjList[MAXV];
typedef struct
{
AdjList adjlist;
int n,e;
} ALGraph;
//将邻接矩阵g转换成邻接表G
void MatToList(MGraph g,ALGraph *G)
{
int i,j,n=g.n;
ArcNode *p;
G=(ALGraph *)malloc(sizeof(ALGraph));
for(i=0;i<n;i++) G->adjlist[i].firstarc=NULL;
for(i=0;i<n;i++)
{
for(j=n-1;j>=0;j--)
{
if(g.edges[i][j]!=INF&&g.edges[i][j]!=0) |
|