Advertisement
fayimora

Recursion

May 24th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.87 KB | None | 0 0
  1. Now we check is n == 0? No so we do another recursive call. 'n' becomes 4.
  2.         Now we check again is n==0? No so we do another recursive call. 'n' becomes 3.
  3.             Now we check again is n==0?No so we do another recursive call. 'n' becomes 2.
  4.                 Now we check again is n==0?No so we do another recursive call. 'n' becomes 1.
  5.                     Now we check again is n==0? No so we do another recursive call. 'n' becomes 0.
  6.                         Now we check again is n==0? Yes so it time to retun back to where we started from
  7.                         //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.
  8.                     What is 'n'? 'n' is 1 so print 1.
  9.                 What is 'n'? 'n' is 2 so print 2.
  10.             What is 'n'? 'n' is 3 so print out 3.
  11.         What is 'n'? 'n' is 4 so print 4.
  12.     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