3.37

From The Algorithm Design Manual Solution Wiki
Revision as of 18:12, 20 September 2020 by Algowikiadmin (talk | contribs) (Created page with "<pre> bool compare(struct node* a, struct node* b) { // 1. both empty -> true if (a==NULL && b==NULL) return(true); // 2. both non-empty -> compare them else if (a!...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
bool compare(struct node* a, struct node* b) {

  // 1. both empty -> true
  if (a==NULL && b==NULL) return(true);   

// 2. both non-empty -> compare them
  else if (a!=NULL && b!=NULL) {
    return(
      a->data == b->data &&
      compare(a->left, b->left) &&
      compare(a->right, b->right)
    );
  }

  // 3. one empty, one not -> false
  else return(false);
}  

--Max 06:41, 25 June 2010 (EDT)


Back to Chapter 3