//拓扑排序
#include <stdio.h>
#include <stdio.h>
#define MAX_VERTEX_NUM 50
#define STACK_SIZE 50
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;//邻接图的信息
typedef struct {
int *base;
int *top;
int stacksize;//堆栈大小
}SqStack;//堆栈结构体
//*****************初始化堆栈**********************
void InitStack(SqStack *S)
{
S->base=(int *)malloc(STACK_SIZE*sizeof(int));
if(!S->base)
exit(1);
S->top=S->base;
S->stacksize=STACK_SIZE;
}
//*****************入栈*************************
void Push(SqStack *S,int e)
{
if(S->top-S->base>=S->stacksize)
exit(1);
*(S->top++)=e;
} [Page]
//*****************出栈************************
void Pop(SqStack *S,int *e)
{
if(S->top==S->base)
exit(1);
*e=*(--S->top);
}
//****************判断栈空************************
int StackEmpty(SqStack *S)
{
if(S->base==S->top)
return 1;
else
return 0;
}
//***********************建立图******************
void CreatGraph(ALGraph *G)
{
int i,n,m;
ArcNode *p;
printf(\"please input the vexnum and arcnum:\");
scanf(\"%d %d\",&G->vexnum,&G->arcnum);
for(i=1;i<=G->vexnum;i++)//初始图的表头结点
{