拓扑排序(C语言 邻接矩阵存储)

本文提供了一段使用C语言实现邻接矩阵存储的拓扑排序的代码。通过创建有向图,计算入度,初始化栈,将入度为0的顶点压入栈中,进行拓扑排序。最后输出拓扑序列,如果输出的顶点数小于图的顶点数,则说明图中存在环。
摘要由CSDN通过智能技术生成
#include "stdafx.h"
#include"malloc.h"
#define MAX_VERTEX_NUM 20
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define OVERFLOW -2
#define OK 1
#define ERROR -1
#define FALSE 0
typedef int VertexType ;
typedef int InfoType;
typedef int Status;
typedef int SElemType;
typedef int Status;
int indegree[20];


typedef struct{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
typedef struct ArcNode{
int adjvex;
struct ArcNode *nextarc;
InfoType *info;
}ArcNode;
typedef struct VNode{
VertexType data;
ArcNode *finrstarc;
}VNode,AdjList[MAX_VERTEX_NUM];
typedef struct{
AdjList vertices;
int vexnum,arcnum;
int kind;
}ALGraph;
ALGraph G; 
Status LocateVex(int v){
for(int i=0;i<G.vexnum;i++)
{
if(G.vertices[i].data==v)
return i;
}
return ERROR;
}
Status InitStack(SqStack &S){
S.base=(SElemTy
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值