i tried to make a binary tree, but when i print it, it shows nothing.
can someone help me? here's the code:
Code:
#include<iostream>
#include<Windows.h>
#include<string>
#include<fstream>
#include<cstdarg>
using namespace std;
struct data
{
int num;
struct data *left, *right;
}*root = NULL;
void insert(int num, struct data *node)
{
if(node == NULL)
{
node = new data;
node->num = num;
node->left = node->right = NULL;
}
else
{
if(num < node->num)
{
insert(num, node->left);
}
else if(num > node->num)
{
insert(num, node->right);
}
}
}
void print(struct data *node)
{
if(node!=NULL)
{
print(node->left);
cout << node->num << " ";
print(node->right);
}
}
int main()
{
insert(6, root);
insert(4, root);
insert(7, root);
insert(3, root);
insert(8, root);
print(root);
cin.get();
return 0;
}