title: function to create array of post order binary tree
body: <p>Im trying to create a recursive function that creates an array of post order integers from a given tree. This is the code:</p>
  <pre><code>//structure
  typedef struct node
  {
      // Each node holds a single integer.
      int data;
  
      // Pointers to the node's left and right children.
      struct node *left, *right;
  } node;
  
  // preorder_recursive is same as postorder_recursive(), except
  // array[i] comes before the recursive calls
  
  int *postorder_recursive(node *root)
  {
      int *array = malloc(sizeof(node) * node_count(root)); // node_count(root) counts nodes in binary tree
      int i = 0;
      if (root == NULL)
          return 0;
  
      while (root != NULL)
      {
          postorder_recursive(root-&gt;left);
          postorder_recursive(root-&gt;right);
          array[i] = root-&gt;data;
          i++;
      }
      return array;
  }
  
  // returns 1 if pre order = post order, returns 0 otherwise
  int compare(node *a, node *b)
  {
      int i = 0;
      int *preArray, *postArray;
      if (node_count(a) != node_count(b))
          return 0;
      preArray = preorder_recursive(a);
      postArray = postorder_recursive(b);
      for (i = 0; i &lt; node_count(a); i++)
      {
          if (preArray[i] != postArray[i])
              return 0;
      }
  
    free(preArray);
    free(postArray);
  
      return 1;
  }
  </code></pre>
  <p>I am not entirely sure if the error is in this function, but if it is, it's probably due to the while loop. Any help would be great.</p>
  <p>Edit: Ive included a lot more code. The purpose of this is to compare an array of post order to an array of pre-order.</p>