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

Recommended Answers

All 2 Replies

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?

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

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.