0
나는 Tarjan 알고리즘을 사용하여 강하게 연결된 구성 요소를 구현하려고합니다. 노드와 가장자리의 링크 된 목록으로 입력을 제공하고 있습니다. 그러나 gcc 컴파일러는 재귀 함수 (반복 루프에서 꼭지점의 인접 노드를 확인)에서 매번 세그먼트 화 오류를 제공합니다.C에서 강력하게 연결된 구성 요소
이 코드에서 잘못된 점은 무엇입니까?
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);
}
}
재귀에서 유효한 종료 조건이 있습니까? 세그먼테이션 결함과 같은 크래시를 찾으려면 디버거를 사용해야합니다. –
당신이 이것을 스스로 디버깅하지 못하게하는 이유는 무엇입니까? https://twitter.com/rkennedy/status/365678718993170433 –
일반적인 코딩 스타일이 부족하거나 불쾌감을주지 않습니다. 첫 번째 코드 줄 중 하나 인'Ver = search_node (Vertex);는'if (NULL == (Ver = search_node)) {return ENOMEM; }'. 당신은 당신의 기능이 성공했는지 여부를 확인하기조차하지 않습니다. 계속 진행하기 전에 코드를 리펙토링해야합니다. – DevNull