赞
踩
- #include<iostream>
- using namespace std;
- typedef struct BiTNode
- {
- char data;
- struct BiTNode* lchild, * rchild;
- }BiTNode, * BiTree;
- void CreatBiTree(BiTree& T, char e)
- {
- if (T == NULL)
- {
- T = new BiTNode;
- T->data = e;
- T->lchild = NULL;
- T->rchild = NULL;
- }
- else
- {
- if (T->data < e)
- CreatBiTree(T->rchild, e);
- else
- CreatBiTree(T->lchild, e);
- }
- }
- void InOrder(BiTree T)
- {
- if (T)
- {
- InOrder(T->lchild);
- cout << T->data;
- InOrder(T->rchild);
- }
- }
- void Find_k(BiTree T, char a)
- {
- if (!T)
- cout << "失败" << endl;
- else if (T->data == a)
- cout << "成功" << endl;
- else if (T->data < a)
- Find_k(T->rchild, a);
- else if (T->data > a)
- Find_k(T->lchild, a);
- }
- int main()
- {
- BiTree T;
- T = NULL;
- int n;
- cin >> n;
- char e;
- while (n--)
- {
- cin >> e;
- CreatBiTree(T, e);
- }
- InOrder(T);
- Find_k(T, a);
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。