Interview Question

Software Developer Interview Yehud (Israel)

given a binary tree how would you mirrorreverse it

Answer

Interview Answer

1 Answer

0

struct node *mirror(struct node *here) {

  if (here == NULL)
     return NULL;
  else {

    struct node *newNode = malloc (sizeof(struct node));

    newNode->value = here->value;
    newNode->left = mirror(here->right);
    newNode->right = mirror(here->left);

    return newNode;
  }

Greg on Mar 30, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.