.n個頂點的有向圖用鄰接矩陣array表示下面是其拓撲排序算法試補充完整
注().圖的頂點號從 開始計 ().indegree 是有n個分量的一維數組放頂點的入度
().函數 crein 用於算頂點入度 ().有三個函數push(data)pop( )check( )其含義為數據 data進棧退棧和測試棧是否空(不空返回否則)
crein( array indegreen)
{ for (i=;i<n;i++) indegree[i]= (()_______)
for(i=i<n;i++)
for (j=;j<n; j++) indegree[i]+=array[()_______][()_______];
}
topsort (arrayindegreen)
{ count= (()_______)
for (i=;i<n;i++) if (()_______) push(i)
while (check( ))
{ vex=pop( ); printf(vex); count++;
for (i=;i<n;i++)
{ k=array()_______
if (()_______ ) { indegree[i]; if (()_______ ) push(i); }
}
}
if( count<n) printf(圖有回路)
} 【南京理工大學 三 (分)】
[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/sjjg/201311/23131.html