```
this code was error.please help me fix it
include <iostream>
include <conio.h>
include <algorithm>
using namespace std;
int a[]={1,5,7,4,9,8};
BST*binary_search_tree;
struct BST{
int value;
BST* left;
BST* right;
};
int search_bst(BST* node,int key){
if(node==NULL)
return -1;
if(key<node->value)
return search_bst(node->left,key);
if(key>node->value)
return search_bst(node->right,key);
else
return node->value;
}
void insert_bst(BST* &treeNode,BST* newNode){
if(treeNode==NULL)
treeNode=newNode;
else if (newNode->value<treeNode->value)
insert_bst(treeNode->left,newNode);
else
insert_bst(treeNode->right,newNode);
}
void inorder_bst(BST* tree){
if(tree==NULL)
return;
inorder_bst(tree->left);
cout<<tree->value<<" ";
inorder_bst(tree->right);
}
void binary_tree_sort(int a,int length){
BST item;
for(int i=0;i<length;i++){
item=new BST();
item->value=a[i];
insert_bst(binary_search_tree,item);}
inorder_bst(binary_search_tree);
}
int main()
{
binary_tree_sort(a,6);
return 0;
}
```

## Recommended Answers

Jump to Post

`BST*binary_search_tree;`

This is an attempt to multiply BST by binary_search_tree. Did you mean that?

Jump to PostI'm about to go to bed, so I've not commented much of the code.

You also need to write a function to free the memory used by each node.

Here's your code, with the global variables moved to inside main()`#include <iostream> //#include <conio.h> //#include <algorithm> //for brevity only …`

## All 5 Replies

gu mi nam
0
Newbie Poster

Moschops
683
Practically a Master Poster
Featured Poster

gu mi nam
0
Newbie Poster

nullptr
167
Occasional Poster

gu mi nam
0
Newbie Poster

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.