Drawing the call stack in a recursive method

Posted by Shaza on Stack Overflow See other posts from Stack Overflow or by Shaza
Published on 2010-04-13T00:30:52Z Indexed on 2010/04/13 0:32 UTC
Read the original article Hit count: 448

Filed under:
|

Hey, I want to draw the call stack for any recursive method, so I've created a schema like this,

recursiveMethod(){
  //Break recursion condition
  if(){
     // Add  value here to the return values' list- No drawing
     return
   }
  else{
    //Draw stack with the value which will be pushed to the stack here
    variable <- recursiveMethod()
   //Clear the drawing which represents the poped value from the stack here
   return variable
}}

Notes:

  1. This schema can draw recursive methods with n recursive call by making the recursive calls in a separate return statements.
  2. returnValues list, is a list which save all the return values, just for viewing issues.

What do you think of this? any suggestions are extremely welcomed.

© Stack Overflow or respective owner

Related posts about recursion

Related posts about algorithm