4.1)download source code: https://github.com/pacosonTang/dataStructure-algorithmAnalysis/tree/master/chapter9/p242_dfs_findArticulation 4.2)source code at a glance:(for complete code , please click the given link above)
4.2.1) 找割點的函數
// "find the articulation point from the given graph"
void findArticulate(Vertex vertex, int depth)
{ int i;AdjTable temp; Vertex adjVertex; visited[vertex] = 1; // update visited status of vertexvertexIndex[vertex] = counter++; // evaluating vertex index with countervertexLow[vertex] = vertexIndex[vertex]; // the 1st rule: evaluating vertex low with countertemp = adj[vertex]; while(temp->next){adjVertex = temp->next->vertex; if(visited[adjVertex]) // judge whether the adjVertes was visited before {if(vertexIndex[vertex] > vertexIndex[adjVertex] && parent[vertex] != adjVertex) {//parent[adjVertex] = vertex; // building back side, attention of condition of building back side above //ex vertex= 3, adjVertex = 0// just for printing effectfor(i = 0; i < depth; i++) printf(" ");printf("vertex[%c]->vertex[%c] (backside) \n", flag[vertex], flag[adjVertex]);// only if there's a backside, we apply the 2rd rule into the graphvertexLow[vertex] = minimum(vertexLow[vertex], vertexIndex[adjVertex]); // the 2rd rule: find lowest vertexIndex[w] among all edges(v, w) }}// if(!visited[adjVertex])// there's the case no backside, andif condition sentences refers to case of backsideelse {parent[adjVertex] = vertex; // just for printing effectfor(i = 0; i < depth; i++) printf(" ");printf("vertex[%c]->vertex[%c] (building edge)\n", flag[vertex], flag[adjVertex]); findArticulate(adjVertex, depth+1);if(vertex != start) // judge whether the vertex is the start (root) ornotif(vertexLow[adjVertex] >= vertexIndex[vertex])printf("\n\t vertex[%c] proves to be an articulation point !", flag[vertex]);vertexLow[vertex] = minimum(vertexLow[vertex], vertexLow[adjVertex]); // the 3rd rule: find lowest verdexLow[w] among all edges(v, w) }temp = temp->next; }
}
4.2.2) 判斷start頂點是否是割點的函數
int isStartArticulation()
{int i; AdjTable temp;Vertex adjVertex; temp = adj[start]; while(temp->next){adjVertex = temp->next->vertex; if(adjVertex == start){temp = temp->next;continue;}dfs(adjVertex, 1); for(i=0; i<size; i++) if(visited[i] != 1) // "refers that the start vertex is the articulation point"return1; temp = temp->next;}return0;
}