Friday, April 25, 2014

Converting a Tree into an Array

Call traverse(root, array, 0);

int traverse(Node root, int[] a, int index)
{
   if(node == NULL)
      return index;
   int x = traverse(root->left, a, index);
   a[x] = root->data;
   x = traverse(root->right, a, x+1);
}

No comments:

Post a Comment