Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Now we check is n == 0? No so we do another recursive call. 'n' becomes 4.
- Now we check again is n==0? No so we do another recursive call. 'n' becomes 3.
- Now we check again is n==0?No so we do another recursive call. 'n' becomes 2.
- Now we check again is n==0?No so we do another recursive call. 'n' becomes 1.
- Now we check again is n==0? No so we do another recursive call. 'n' becomes 0.
- Now we check again is n==0? Yes so it time to retun back to where we started from
- //the most interesting part here is that the previous value of n still exist but on the stack so we have to go through them all by backtracking.
- What is 'n'? 'n' is 1 so print 1.
- What is 'n'? 'n' is 2 so print 2.
- What is 'n'? 'n' is 3 so print out 3.
- What is 'n'? 'n' is 4 so print 4.
- What is n? 'n' is 5 so print 5. Here we stop because we dont have any other thing on the stack
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement