All pastes #42647 Raw Edit

Untitled

public text v1 · immutable
#42647 ·published 2006-02-21 11:56 UTC
rendered paste body
Write C code to determine if two trees are identical




Here is a C program using recursion


int identical(struct node* a, struct node* b) 
{ 
  if (a==NULL && b==NULL){return(true);} 
  else if (a!=NULL && b!=NULL) 
  { 
    return(a->data == b->data && 
           identical(a->left, b->left) && 
           identical(a->right, b->right)); 
  } 
  else return(false); 
}