Witam mam problem z kodem do sortowania drzewem BST, coś mi w nim nie chce działać. Mam jeszcze jedno pytanie jak tam wstawić funkcję badającą czas działania algorytmu i zliczającą ilość porównań i zamian
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
struct node
{
int val;
node*left,*right;
}
void add(node *root, int x)
{
while(true)
{
if(x<root->val)
{
if(root->left==NULL)
break;
root=root->left;
}
else return;
}
node*new=new node;
new->val=x;
new->left;
new->right=NULL;
if(x<node->val)
{
node->left=new;
else
node->right=new;
}
}
void show(node *root)
{
if(root->left!=NULL)
show(root->left);
cout<<root->val<<" ";
if(root->right!=NULL)
show(root->right);
}
void del(node *root)
{
if(root->left!=NULL)
del(root->left);
if(root->right!=NULL)
del(root->right);
delete root;
}
int main()
{
srand(time(NULL));
node*root=new node;
int n=10
root->val=2
root->left=NULL;
root->right=NULL;
for(int i=0; i<n-1; i++)
{
add(root, rand()%20);
}
show(root);
del(root);
cout<<endl;
system("pause");
return 0;
}