图的拓扑排序问题
/* Note:Your choice is C IDE */#include "stdio.h"
#include<malloc.h>
#define MAX 100
typedef struct edgesnode
{
int adjvex;
int value;
struct edgesnode *next;
}arcnode;
typedef struct vexnode
{
char data;
int count;
arcnode *firsthead;
}headnode;
typedef struct
{
int n,e;
headnode adjlist[MAX];
}graphlist;
int creatgraph(graphlist *g)
{
int i,b,t,w;
arcnode *p;
printf("顶点数和边数:");
scanf("%d%d",&g->n,&g->e);
for(i=0;i<g->n;i++)
{
getchar();
printf("序号为%d的顶点信息:",i);
scanf("%c",&g->adjlist[i].data);
g->adjlist[i].firsthead=NULL;
}
for(i=0;i<g->e;i++)
{
printf("序号为%d的边=>",i);
printf("起点号 终点号 权值:");
scanf("%d%d%d",&b,&t,&w);
if(b<g->n&&t<g->n&&w>0)
{
p=(arcnode *)malloc(sizeof(arcnode));
p->value=w;p->adjvex=t;
p->next=g->adjlist[b].firsthead;
g->adjlist[b].firsthead=p;
}
else
{
printf("输入错误:");
return 0;
}
}
return 1;
}
void topsort(headnode adj[],int n)
{
int i,j;
int st[MAX],top=0;
arcnode *p;
for(i=0;i<n;i++)
if(adj[i].count==0)
{ top++;st[top]=i; }
while(top!=0)
{
i=st[top];top--;
printf("%d",i);
p=adj[i].firsthead;
while(p)
{
j=p->adjvex;
adj[j].count--;
if(adj[j].count==0)
{ top++;st[top]=j; }
p=p->next;
}
}
}
void main()
{
graphlist g;
headnode adj[MAX];
creatgraph(&g);
topsort(adj,g.n);
}
大家帮我看看应该怎么改才能运行。