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

>>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

Hi Ancient Dragon ,

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

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 );
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.