So I have to get the elements under odd indices in reverse.
I have written a function to get me odd index elements but I am not sure how to make them return in reverse.
I have to do this in one function and it has to be recursive.
So I have to get the elements under odd indices in reverse.
I have written a function to get me odd index elements but I am not sure how to make them return in reverse.
I have to do this in one function and it has to be recursive.
What you're doing is taking the first element then append the rest of result. If you do it other way around, then you'd get the reversed list. Thus, You can get the reverse list simply swapping the append
's arguments.
NOTE: The code costs O(n^2) and consumes stack for each recursive call. So it's better to make it tail recursive, then the Scheme implementation you're using optimises it not to consume stack.