//
#include
#include
#include "binary_tree.h"
int _tmain(int argc, _TCHAR* argv[])
{
//初始化二叉树类
Binary_Tree * pBTree = new Binary_Tree();
//创建一个二叉树
while(1)
{
char strKey[100];
char strValue[100];
printf("输入Key值(EXIT结束):");
scanf("%s", strKey);
if(strcmp(strKey, "EXIT") == 0)
{
break;
}
printf("输入Value值:");
scanf("%s", strValue);
//在二叉树中插入一个节点
bool ret = pBTree->InsertIntoTree(std::string(strKey), std::string(strValue));
if(!ret)
{
printf("已有此Key值的记录存在\n\n");
}
}
//在已创建的二叉树中查找
while(1)
{
char strKey[100];
std::string stringValue = "";
printf("输入需要查找的Key值(EXIT结束):");
scanf("%s", strKey);
if(strcmp(strKey, "EXIT") == 0)
{
break;
}
//在二叉树中查找Key之对应的Value
bool ret = pBTree->SearchInTree(std::string(strKey), stringValue);
if(!ret)
{
printf("无此Key值的记录存在\n\n");
}
else
{
printf("Key = %s\nValue = %s\n\n", strKey, stringValue.c_str());
}
}
delete pBTree;
return 0;
} 22299希望对你有帮助!