- #1
gfd43tg
Gold Member
- 950
- 50
Homework Statement
Write a function called reverse that uses recursion to reverse any one-dimensional string array.
Homework Equations
The Attempt at a Solution
Code:
function out = reverse(str)
if length(str) == 0
out = str;
else
out = [str(end) reverse(str(1:end-1))];
end
I am having difficulty understanding how this recursion tree will look. I am using a break point to understand the behavior, and it seems like every iteration it is taking off the last letter of the string until the string is empty, then it is filling it back in reverse order. But I can't put that into the form of a tree.