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.
精彩评论