typedef struct{
int last_one;
int length_of_way;
}NODE;
Status Reclear_Queue(Queue &Q,int* indegree,int N){
ClearQueue(Q);
for(i = 0;i < N;i++)
if(!indegree[i]) EnQueue(Q,i);
return OK;
}//Reclear_Queue
Status Find_longest_way_DAG(MGraph G){
//求以邻接矩阵存储的有向无环图中的最长路径
NODE way[G.vexnum];
FindInDegree(G,indegree);//求入度序列
for(i = 0;i < G.vexnum;i++){//路径初始化
way[i].last_one = -1
if(!indegree[i]) way[i].length_of_way = 0;
else way[i].length_of_way = -1;
}//for
InitQueue(Q);
int processed = 0;
while(processed < G.vexnum){//找路
Reclear_Queue(Q,indegree,G.vexnum);
int Queuel = QueueLength(Q);
processed += Queuel;
for(i = 0;i < Queuel;i++){
DeQueue(S,start);
for(j = 0;j < G.vexnum;j++){
if(G.arcs[start][j]){//这里的假设是相邻则为关联边长度,不相邻则为0
indegree[j]--;
if(way[st
求以邻接矩阵存储的有向无环图中的最长路径
最新推荐文章于 2021-08-09 10:14:40 发布