title: C++ - Min heap implementation and post order traversal
body: <p>So I have this small program that creates a min heap and insert values based on user input. If the users says change value 10 to 20, the program should change all occurrences of 10 to 20 and then heapify. When the user gives the print command the program should traverse the tree in postorder and print all the values. So I have written program but its giving me the incorrect output when I print. What am I doing wrong here: </p>
  
  <pre><code>int pArray[500]; 
  int i = 0;
  
  //Definition of Node for tree
  struct TNode {
      int data; 
      TNode* left;
      TNode* right;
  };
  
  void Heapify(TNode* root, TNode* child);
  
  // Function to create a new Node in heap
  TNode* GetNewNode(int data) {
      TNode* newNode = new TNode();
      newNode-&gt;data = data;
      newNode-&gt;left = newNode-&gt;right = NULL;
      return newNode;
  }
  
  // To insert data in the tree, returns address of root node 
  TNode* Insert(TNode* root,int data) {
      if(root == NULL) { // empty tree
          root = GetNewNode(data);
      }
      // if the left child is empty fill that in
      else if(root-&gt;left == NULL) {
          root-&gt;left = Insert(root-&gt;left,data);
      }
  
      // else, insert in right subtree. 
      else if(root-&gt;right == NULL){
          root-&gt;right = Insert(root-&gt;right,data);
      }
  
      else {
          root-&gt;left = Insert(root-&gt;left,data);
      }
  
      Heapify(root, root-&gt;left);
      Heapify(root, root-&gt;right);
  
      return root;
  }
  
  void Heapify(TNode* root, TNode* child){
     if(root != NULL &amp;&amp; child != NULL){
          if(root-&gt;data &gt; child-&gt;data){
              int temp = child-&gt;data;  
              child-&gt;data = root-&gt;data;
              root-&gt;data = temp;
          }
      } 
  }
  
  void Change(TNode* root,int from, int to) {
  
      if (root == NULL) 
          return;
  
      else if (root-&gt;data == from)
          root-&gt;data = to;
  
      Change(root-&gt;left, from, to);
      Change(root-&gt;right, from, to);
  
  }
  
  void postOrder(TNode* n){
    if ( n ) {
         postOrder(n-&gt;left);
         postOrder(n-&gt;right);
         pArray[i] = n-&gt;data;
         i++;
      }  
  } 
  </code></pre>