我正在使用 Tarjan 算法实现强连接组件。我将输入作为节点和边的链接列表。但是,gcc 编译器每次在递归函数中都会给出分段错误(在 while 循环中,我正在检查顶点的相邻节点)。
知道这段代码有什么问题吗?
void strongconnect(int Vertex)
{
struct sc_node * Ver;
Ver = search_node(Vertex);
Ver->sc_index = ind; //accessing the index information of node
Ver->sc_lowlink = ind; // accessing the link information of node
//Ver->visited = 1;
ind++;
int w;
push(Vertex);
struct sc_node * to_link, *to_link1;
int to_lowlink,to_index;
int flowlink;
int min;
int from_index;
edge_trav = edge_head;
while(edge_trav != NULL) //accessing linked list of edges
{
if(edge_trav->from_vertex == Vertex)
{
to_link = search_node(edge_trav->to_vertex);
to_lowlink = to_link->sc_lowlink;
to_index = to_link->sc_index;
to_link1 = search_node(Vertex);
flowlink = to_link1->sc_lowlink;
from_index = to_link1->sc_index;
if(to_index == 0)
{ Vertex = to_link->sc_data;
printf("INSIDE RECURSION");
strongconnect(Vertex); // recursive loop
min = minimum(flowlink,to_lowlink);
to_link1->sc_lowlink = min;
}
else
{
min = minimum(flowlink, from_index);
to_link1->sc_lowlink = min;
} }
edge_trav = edge_trav->next;
}
Ver = search_node(Vertex);
if(Ver->sc_lowlink == Ver->sc_index)
{
do
{
w = pop();
printf("%d\t",w);
}while(w != Vertex);
}
}