Example #1
0
/* Driver function to test above functions */
int main() 
{ 
  struct node *root = NULL; 

  /* Constructing tree given in the above figure 
        10 
       /  \ 
      30   15 
     /      \ 
    20       5   */
  root = newNode(10); 
  root->left = newNode(30); 
  root->right = newNode(15); 
  root->left->left = newNode(20); 
  root->right->right = newNode(5); 

  // convert Binary Tree to BST 
  binaryTreeToBST (root); 

  printf("Following is Inorder Traversal of the converted BST: \n"); 
  printInorder (root); 

  return 0; 
} 
/* Driver function to test above functions */
int main()
{
    struct node *root = NULL;
 
    /* Constructing tree given in the above figure
          1
         /  \
        2    4
       /      \
      3       5   */
    root = newNode(1);
    root->left = newNode(2);
    root->right = newNode(3);
    root->left->left = newNode(4);
    root->right->right = newNode(5);
 
    // convert Binary Tree to BST
    binaryTreeToBST (root);
 
    printf("Inorder Traversal of the converted BST: \n");
    printInorder (root);
 
    return 0;
}