Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)

简介: Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)

题目链接:点击打开链接

题目大意:略。

解题思路:略。

AC 代码

boolTopSort( LGraphGraph, VertexTopOrder[] )
{
PtrToAdjVNodee;
inttop=0, cnt=0, in[Graph->Nv+10];
for(inti=0;i<Graph->Nv;i++) in[i]=0;
Vertex*sk;
sk=(Vertex*)malloc(Graph->Nv*sizeof(Vertex));
for(inti=0;i<Graph->Nv;i++)
    {
for(e=Graph->G[i].FirstEdge; e; e=e->Next)
        {
intk=e->AdjV;
in[k]++;
        }
    }
for(inti=0;i<Graph->Nv;i++)
if(in[i]==0) sk[++top]=i;
while(top!=0)
    {
inttp=sk[top--];
TopOrder[cnt++]=tp;
for(e=Graph->G[tp].FirstEdge; e; e=e->Next)
        {
intk=e->AdjV;
if(!(--in[k]))
sk[++top]=k;
        }
    }
if(cnt<Graph->Nv) return0;
return1;
}
目录
相关文章
|
存储 容器
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
222 0
Data Structures and Algorithms (English) - 7-18 Hashing - Hard Version(30 分)
|
机器学习/深度学习 算法
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
216 0
Data Structures and Algorithms (English) - 7-28 Review of Programming Contest Rules(30 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
Data Structures and Algorithms (English) - 6-8 Percolate Up and Down(20 分)
105 0
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
Data Structures and Algorithms (English) - 6-15 Iterative Mergesort(25 分)
191 0
Data Structures and Algorithms (English) - 6-10 Sort Three Distinct Keys(30 分)
Data Structures and Algorithms (English) - 6-10 Sort Three Distinct Keys(30 分)
104 0
|
C++
Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)
Data Structures and Algorithms (English) - 6-9 Sort Three Distinct Keys(20 分)
120 0
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
Data Structures and Algorithms (English) - 7-12 How Long Does It Take(25 分)
114 0
Data Structures and Algorithms (English) - 6-1 Deque(25 分)
Data Structures and Algorithms (English) - 6-1 Deque(25 分)
101 0
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
Data Structures and Algorithms (English) - 6-2 Two Stacks In One Array(20 分)
144 0
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
Data Structures and Algorithms (English) - 7-9 Huffman Codes(30 分)
102 0