Saturday, 12 April 2014

Convert a tree to array


Here is the simple code for converting a BST to array of numbers:

/* Converting a BST into an Array */
void TreeToArray(struct Tree *node, int a[]){
static int pos = 0;

if(node){
TreeToArray(node->left,a);
a[pos++] = node->data;
TreeToArray(node->right,a);
      }
}

For other tree operations and complete code refer to : click here

No comments:

Post a Comment

AWS Data Pipeline Services

https://www.youtube.com/watch?v=tykcCf-Zz1M