#include
#include
using namespace std;
struct BitTree{
int data;
BitTree *lchild,*rchild;
};
void InsertBST(BitTree *T,int k)
{
if (T == NULL) { T = new BitTree; (*T).data = k; (*T).lchild = NULL; (*T).rchild = NULL; }
else if (k == (*T).data) return;
else if (k < (*T).data) InsertBST((*T).lchild, k);
else InsertBST((*T).rchild, k);
}
void CreateBST(BitTree *T,int n)
{
int k;
for (int i = 1; i <= n; i++)
{
cin >> k;
InsertBST(T, k);
}
}
void Preorder(BitTree *T)
{
if (T != NULL)
{
cout << (*T).data << ' ';
Preorder((*T).lchild);
Preorder((*T).rchild);
}
}
void main()
{
int t;
cout << "输入多少数据?:"; cin >> t;
BitTree *T = NULL;
CreateBST(T, t);
Preorder(T);
system("pause");
}
为什么不对呢 每次执行完 InsertBST时 依旧T=NULL 但是我用的是地址传递的方式调用函数的吧
我是初学者 求大神们帮助!~