0

He guys,

I am trying to figure out what is wrong with this code for level traversal in binary tree in C. I would really appreciate any help or suggestion or changes in my code.

status level_traverse( tree T, status( *p_func_f ) () ) {

  tree *node ;
  queue q ;
  
  if( init_queue( &q ) == ERROR ) return ERROR ;

  if( qadd( &q, T ) == ERROR ) return ERROR ;

  while( ! empty_queue( &q ) ) {

    if( node != NULL ) {
      qremove ( &q, ( generic_ptr * ) &node ) ;
      qadd( &q, ( generic_ptr ) LEFT( T ) ) ;
      qadd( &q, ( generic_ptr ) RIGHT( T ) ) ;
    }
  }

  return OK ;

}

I already have it printing out in my main.c and we are supposed to use it so it returns status. If you guys know any other way to do it, please let me know. I will try that too..

Thanks

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by abhimanipal
0

I don't know what is wrong. You do. Does it not compile? does it crash at runtime? does it not produce the desired results?

0

Also what are these functions qinit, qremove, qadd ??
Are you sure there are no errors in these functions ?

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.