Hi,everybody!I am working on a program,which merges two binary search trees in a new one,but I receive the same error every time for parameters t1 and t2:
Run-Time Check Failure #3 - The variable 't2' is being used without being initialized.
Run-Time Check Failure #3 - The variable 't1' is being used without being initialized.
Here`s the code:
#include<iostream>
#include<stdlib.h>
using namespace std;
struct elem
{ int key;
elem *left;
elem *right;
} *t1=NULL, *t2=NULL, *t3=NULL;
void add(int t1, elem *&t2)
{
if(t2==NULL)
{
t2=new elem;
t2->key=t1;
t2->left=NULL;
t2->right=NULL;
}
else
{
if(t1<t2->key)
add(t1,t2->left);
else
if(t1>t2->key)
add(t1,t2->right);
}
}
void printnode(int n, int h)
{
for(int i=0;i<h;i++)
cout<<"\t";
cout<<n<<endl;
}
However further in the code in main (that shall be declared as int main()) you defined local variables with the same names as the global variables and did not initialized them.
I fixed that but still got Error 't1' : 'elem *' differs in levels of indirection from 'int' d:\microsoft visual studio 2010 express\dggsgsgs\dggsgsgs\fgsfgddfg.cpp 74.This happens even when I have initialized the local variables t1,t2 and t3
The errors are gone,thank you,but in main, the function,which merges the trees, doesn`1t work: cout<<"The combined tree is:"<<endl;
in_order_traversal(t3);
show(t3,0);