数据结构 拓扑排序问题
来源:百度知道 编辑:UC知道 时间:2024/06/12 02:27:04
c0-->c6-->c7-->c8
c0-->c2-->c3-->c8
c1-->c2
c1-->c4-->c5
c3-->c5
c4-->c3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Node
{
intadjvex; //该弧所指向的顶点的位置
struct Node*next; //指向下一个条弧的指针
}ArcNode;
typedef struct Vertex
{
intindegree; //存放顶点的入度
ArcNode*first_arc; //指向第一条依附该顶点的弧的指针
}VNode;
int iarray; //用数组存储拓扑序列
typedef struct
{
int *base;
int *top;
}Stack;
Stack S; //用栈暂存所有入度为0的顶点
void InitStack(Stack *S)
{
S->base= (int *)malloc(10 * sizeof(int));
S->top =S->base;
}
void Push(Stack *S, int e)
{
*S->top++ = e;
}
void Pop(Stack *S, int *e)
{
*e =*--S->top;
}
void create_graph(VNode *vlist, int n) //用邻接表构造图
{
int i,position;