c语言实现拓扑排序(《数据结构》算法7.12)

邻接表+拓扑排序,输出的是无向图的拓扑有序序列。

代码如下:

#include<stdio.h>
#include<stdlib.h>
#include<stack>
#define MAX_VERTEX_NUM 100
using namespace std;
int indegree[MAX_VERTEX_NUM];
stack<int>s;
typedef struct ArcNode{
	int adjvex;//该边的另一个顶点的位置 
	struct ArcNode *nextarc; //指向下一条边 
}ArcNode;
typedef struct VNode{
	int data;//顶点的值 
	ArcNode *firstarc;//指向第一条依附该顶点的边的指针 
}VNode,AdjList[MAX_VERTEX_NUM];
typedef struct{
	AdjList vertices;//顶点数组 
	int vexnum,arcnum;
}ALGraph;
int LocateVex(ALGraph G,int v){//定位函数 
	for(int i=0;i<G.vexnum;i++){
		if(v==G.vertices[i].data)return i;
	} 
}
void CreateDG(ALGraph &G){
	ArcNode *p;
	int i,j,k,v1,v2;
	printf("分别输入顶点个数和边的数目:\n");
	scanf("%d%d",&G.vexnum,&G.arcnum);
	printf("分别输入各个顶点值:\n");
	for(i=0;i<G.vexnum;i++){
	scanf(
  • 2
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值