순환 이중 연결리스트에서 값 20을 갖는 모든 노드를 계산하는 다음 재귀 함수가 있습니다. 안전 문제를 방지하기 위해 이것을 꼬리 재귀 함수로 변환해야합니다. 같은 것을 도와주세요. 감사합니다재귀 함수를 꼬리 재귀로 변환
이 일반적으로 그렇게 실제로 도움이되지 않습니다 꼬리 재귀 형태로 기능을 번역, 꼬리 재귀를 인식하지 못하는 C. C 구현과 같은int count(node *start)
{
return count_helper(start, start);
}
int count_helper(node *current, node *start)
{
int c;
c = 0;
if(current == NULL)
return 0;
if((current->roll_no) == 20)
c = 1;
if(current->next == start) return c;
return (c + count_helper(current->next, start));
}
이 숙제입니까? –
숙제가 아니라면 여기서 재귀를 수행 할 이유가 없습니다. –
가능한 [반복적 인 함수를 꼬리 재귀로 변환] (http://stackoverflow.com/questions/7945313/converting-a-recursive-function-to-tail-reursive) 및 [반복 함수를 재귀 적으로 변환] (http://stackoverflow.com/questions/7939493/converting-an-iterative-function-to-reursive). –