"unsorted array to bst" Code Answer's
You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "unsorted array to bst" answered properly. Developers are finding an appropriate answer about unsorted array to bst related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like unsorted array to bst. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on unsorted array to bst.
unsorted array to bst
#include<iostream>
using namespace std;
typedef struct node
{
int value;
node * pLeft;
node * pRight;
node(int val = 0)
{
value = val;
pRight = NULL;
pLeft = NULL;
}
}node;
void insert(node ** pRoot, int val)
{
if(*pRoot == NULL)
*pRoot = new node(val);
else if((*pRoot)->value <= val)
insert(&((*pRoot)->pRight), val);
else if((*pRoot)->value > val)
insert(&((*pRoot)->pLeft), val);
}
node * getBST(int * arr, int size)
{
node * pRoot = NULL;
for(int i = 0; i < size; i++)
insert(&pRoot, arr[i]);
return pRoot;
}
void inOrderTraversal(node * pRoot)
{
if(pRoot && pRoot->pLeft)
inOrderTraversal(pRoot->pLeft);
if(pRoot)
std::cout<<pRoot->value<<" , ";
if(pRoot && pRoot->pRight)
inOrderTraversal(pRoot->pRight);
}
int main()
{
int arr[] = {10,5,15,5,6,7,8,89};
node * pRoot = getBST(arr, sizeof(arr)/sizeof(int));
inOrderTraversal(pRoot);
std::cout<<std::endl;
return 0;
}
All those coders who are working on the C++ based application and are stuck on unsorted array to bst can get a collection of related answers to their query. Programmers need to enter their query on unsorted array to bst related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about unsorted array to bst for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of unsorted array to bst while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "unsorted array to bst". Visit this developer's friendly online web community, CodeProZone, and get your queries like unsorted array to bst resolved professionally and stay updated to the latest C++ updates.