0

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

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Hamrick
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

0

Hi Ancient Dragon ,

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

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 );
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.