
Status Push_SeqStack(SeqStack &s, ElemType x){
if(s.top == MAXSIZE -1){
return ERROR;
}
s.top++;
s.elem[s.top] = x;
return OK;
}//入栈,x入到s栈中
void topsort( ALGraph &G)
{
int i,v,w;
int cnt=0;//计数器初始化为0
EdgeNode *ptr;
SeqStack st;
InitStack_Sq(st);
for(i=0;i<G.n;i++)
{
if(G.adjlist[i].Indegree==0)
Push_SeqStack(st,i);
}
while(!Empty_Sq(st))
{
Pop_SeqStack( st, v);//出栈一次,出栈元素放在v中
printf("%s ",G.adjlist[v].vertex);
cnt++;
ptr=G.adjlist[v].firstedge; //ptr指向第一个边结点
while(ptr!=NULL)//只要有边
{
w=ptr->adjvex;
G.adjlist[w].Indegree--;
if(G.adjlist[w].Indegree==0)
Push_SeqStack(st,w);
ptr=ptr->next;
}
}
if(cnt<G.n)
printf("后续无法输出!\n");
}