开发者

How do I handle recursion and arrays in C?

So I have the following recursive function:

int printSeq(int last[], int n, int arr[], int longest){

     if(last[longest]==longest) return arr[longest];
     printf("%d ", printSeq(last, n, arr, last[longest]));
}

last is an array with locations pointing to array. Longest is the current locatio开发者_开发问答n.

However when I run it I get strange values that are not in the array. Am I missing something?

The base case is when the last[longest] points to its own location


The function doesn't return any value after a printf. This results in Undefined Behavior.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜