Description: #include <stdio.h>
#include <string.h>
#include <windows.h>
struct BTree {
int data
struct BTree* left
struct BTree* right
} //end struct BTree
BTree* CreateLeaf(int number)
{
BTree* l = new BTree
l->data = number
l->left = 0
l->right = 0
return l
}//end CreateLeaf
void append(BTree** root, int number)
{
if (!root) return
BTree* t =*root
if (!t) {
*root = CreateLeaf(number)
return
}//end if
while(t) {
if(number == t->data ) return //ignore duplicated elements.
if(number < t->data ) {
if(!t->left ) {
t->left = CreateLeaf(number)
return
}//end if
t = t->left
}else{
if(!t->right ) {
t->right = CreateLeaf(number)
return
}//end if
t = t->right
}//end if
}//end while
}//end append
void PrintLeaf(const BTree* root)
{
if (!root) return
if (root->left ) PrintLeaf(root->left )
printf(" d\t", root->data)
if (root->right ) PrintLeaf(root->right )
To Search:
File list (Check if you may need any files):
新建文件夹\Debug\vc60.idb
..........\.....\vc60.pdb
..........\.....\平衡二叉树.exe
..........\.....\平衡二叉树.ilk
..........\.....\平衡二叉树.obj
..........\.....\平衡二叉树.pch
..........\.....\平衡二叉树.pdb
..........\平衡二叉树.cpp
..........\平衡二叉树.dsp
..........\平衡二叉树.dsw
..........\平衡二叉树.ncb
..........\平衡二叉树.opt
..........\平衡二叉树.plg
..........\Debug
新建文件夹