954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

good recursive program

Hi All,

can anybody provide me recursive implementation of depth first search..

one more question .. is it possible to code any problem with recursion without using global variable..
i just need general views about good recursive program..
thankx

johnray31
Junior Poster in Training
68 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

>>recursive implementation of depth first search
read this

>> is it possible to code any problem with recursion without using global variable
yes, pass them as a function parameter

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

Hi Ancient Dragon ,

thankx for ur reply... i want to modify my statement once..
is it bad to use static variables in recursive program

johnray31
Junior Poster in Training
68 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

It's not bad to do anything. Even global variables aren't bad. They can make it harder to troubleshoot or reuse your code, but saying they're bad is weird. You have the same issue with static variables. They're not right for a function that has to be re-entrant but it they solve the problem, what's the problem? :)

You could use parameters to do the same thing if you don't like either global variables or static variables.

void function( int limit, int depth ) {
  if ( limit == 0 ) {
    return;
  }

  if ( depth % 2 == 0 ) {
    puts( "Do something special at even depths" );
  }

  function( limit - 1, depth + 1 );
}
Hamrick
Posting Whiz
325 posts since Jun 2007
Reputation Points: 180
Solved Threads: 34
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You