This week and last week we learnt recursion and tracing recursion.
It is amazing, for example, the method calls itself in its body, which makes a loop. It is more convenient than to use recursion than for loop or while loop, however, the thinking process is much more complicated than for loop and while loop.
I found myself have trouble writing complex recursion function, but I realized tracing recursion is quite useful. I guess that's the reason why we learnt how to trace them at first.
Here are the details and steps about my solution. When I encounter some problem when writing recursive function, I try to "tracing" it firstly. For instance, try to figure out what I want at each step. For most of the time, I need to guess with my instinct, then trace it. When error occurs, I stop tracing and then fix my guess then restart. After several loops, I can find the right answer. However, it's kind of time-wasting, but is still quite useful.
没有评论:
发表评论