‘壹’ C语言二叉树递归算法怎么做
#include<stdio.h>
#include<string.h>
structtreenode{
intvalue;
treenode*left;
treenode*right;
};
typedeftreenode*BiTree;
voidvisit(treenode*node)
{
printf("%2d",node->value);
}
//结点总数
intnode(BiTreeT)
{
if(!T){
return0;
}
returnnode(T->left)+node(T->right)+1;
}
//前序
voidpreOrder(BiTreeT)
{
if(T){
visit(T);
preOrder(T->left);
preOrder(T->right);
}
}
//中序
voidinOrder(BiTreeT)
{
if(T){
inOrder(T->left);
visit(T);
inOrder(T->right);
}
}
//后序
voidpostOrder(BiTreeT)
{
if(T){
postOrder(T->left);
postOrder(T->right);
visit(T);
}
}
//叶子节点数
intleafnode(BiTreeT)
{
if(T){
if(!T->left&&!T->right)
return1;
else
leafnode(T->left)+leafnode(T->right);
}else{
return0;
}
}
intheight(BiTreeT)
{
if(T){
intlh=height(T->left);
intrh=height(T->right);
return(lh>rh?lh:rh)+1;
}else{
return0;
}
}
intmain()
{
return0;
}
‘贰’ 二叉树c语言实现
#include<iostream.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
char data;
struct node *lchild,*rchild;//
}BiTNode,*BiTree;
void CreatBiTree(BiTree &T)
{
char ch;
ch=getchar();
if (ch == ' ')
T = 0;
else {
T=(BiTNode*)malloc(sizeof(BiTNode));
T->data=ch;//生成根节点
CreatBiTree(T->lchild);//构造左子树
CreatBiTree(T->rchild);//构造右子树
}
}
void preorder(BiTree T)//前序遍历
{
if (T!=NULL){
printf ("%c",T->data);
preorder(T->lchild);
preorder(T->rchild);
}
}
void inorder(BiTree T)//中序遍历
{
if (T!=NULL){
inorder(T->lchild);
printf ("%c",T->data);
inorder(T->rchild);
}
}
void postorder(BiTree T)//后序遍历
{
if (T!=NULL){
postorder(T->lchild);
postorder(T->rchild);
printf ("%c",T->data);
}
}
void main ()
{
cout<<"请输入要创建的二叉树包括空格:"<<endl ;
BiTree T;
CreatBiTree(T);//创建二叉树
cout<<"前序遍历的结果为:"<<endl;
preorder(T);
cout<<endl;
cout<<"中序遍历的结果为:"<<endl;
inorder(T);
cout<<endl;
cout<<"后序遍历的结果为:"<<endl;
postorder(T);
}
‘叁’ 数据结构c语言习题。编写一个函数以二叉查找树T和两个有序的关键字 k1,
//创建二叉树的原数组数据:40206010305070
//前序遍历序列:40201030605070
//中序遍历序列:10203040506070
//后序遍历序列:10302050706040
//输入关键字k1,k2的数值:3050
//打印的结果:
//403050
//
//二叉树示意图:
//
//40
///
//2060
////
//10305070
#include"stdio.h"
#include"stdlib.h"
structTree
{
intdata;
structTree*left;
structTree*right;
};
typedefstructTreeTreeNode;
typedefTreeNode*Bitree;
BitreeinsertNode(Bitreeroot,intdata)//插入结点
{
Bitreenewnode;
Bitreecurrent;
Bitreeback;
newnode=(Bitree)malloc(sizeof(TreeNode));
if(newnode==NULL)
{
printf(" 动态分配内存出错. ");
exit(1);
}
newnode->data=data;
newnode->left=NULL;
newnode->right=NULL;
if(root==NULL)
{
returnnewnode;
}
else
{
current=root;
while(current!=NULL)
{
back=current;
if(current->data>data)
current=current->left;
else
current=current->right;
}
if(back->data>data)
back->left=newnode;
else
back->right=newnode;
}
returnroot;
}
BitreecreateTree(int*data,intlen)//创建二叉树(非递归)
{
Bitreeroot=NULL;
inti;
for(i=0;i<len;i++)
{
root=insertNode(root,data[i]);
}
returnroot;
}
voidpreOrder(Bitreeptr)//先序遍历(递归法)
{
if(ptr!=NULL)
{
printf("%d",ptr->data);
preOrder(ptr->left);
preOrder(ptr->right);
}
}
voidinOrder(Bitreeptr)//中序遍历(递归法)
{
if(ptr!=NULL)
{
inOrder(ptr->left);
printf("%d",ptr->data);
inOrder(ptr->right);
}
}
voidpostOrder(Bitreeptr)//后序遍历(递归法)
{
if(ptr!=NULL)
{
postOrder(ptr->left);
postOrder(ptr->right);
printf("%d",ptr->data);
}
}
//根据关键字k1和k2,进行区间查找(递归法)
voidbtreeSearch(Bitreeptr,intk1,intk2)
{
if(ptr!=NULL)
{
if(ptr->data<k1&&ptr->data<k2)
{
btreeSearch(ptr->right,k1,k2);
}
elseif(ptr->data==k1&&ptr->data<k2)
{
printf("%d",ptr->data);
btreeSearch(ptr->right,k1,k2);
}
elseif(ptr->data>k1&&ptr->data<k2)
{
printf("%d",ptr->data);
btreeSearch(ptr->left,k1,ptr->data);
btreeSearch(ptr->right,ptr->data,k2);
}
elseif(ptr->data>k1&&ptr->data==k2)
{
printf("%d",ptr->data);
btreeSearch(ptr->left,k1,k2);
}
elseif(ptr->data>k1&&ptr->data>k2)
{
btreeSearch(ptr->left,k1,k2);
}
elseif(ptr->data==k1&&ptr->data==k2)
{
printf("%d",ptr->data);
}
else
{
printf("其它情况,当前节点的数值是%d",ptr->data);
}
}
}
intmain()
{
BitreeT=NULL;//T是二叉查找树
intdata[]={40,20,60,10,30,50,70};
intlen;
inti;
intk1,k2;//关键字k1,k2
inttmp;
len=sizeof(data)/sizeof(int);
printf("创建二叉树的原数组数据:");
for(i=0;i<len;i++)
{
printf("%d",data[i]);
}
T=createTree(data,len);//创建二叉树
printf(" 前序遍历序列:");
preOrder(T);
printf(" 中序遍历序列:");
inOrder(T);
printf(" 后序遍历序列:");
postOrder(T);
printf(" 输入关键字k1,k2的数值:");
scanf("%d%d",&k1,&k2);
if(k1>k2)
{
tmp=k1;
k1=k2;
k2=tmp;
}
//根据关键字k1和k2,进行区间查找(递归法)
btreeSearch(T,k1,k2);
printf(" ");
return0;
}
‘肆’ 二叉查找树遍历问题
你好
很高兴为你解答
答案是:下面是我的答案,已经在VC2010下测试通过 。
满意请采纳,谢谢
#include "stdafx.h" /*VC用的头文件,在其它C中请删除*/
#include <stdio.h> /*输入六个整数45、24、53、12、37、9,插入数据元素13,删除数据元素24和53 */
#include <stdlib.h>
typedef struct BiTNode/*结点结构 */
{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
BiTree Insert(BiTree T,int e)/*插入操作*/
{
BiTree p=T, f=NULL, s;
s=(BiTree)malloc(sizeof(BiTNode));
s->data=e;
s->lchild=s->rchild=NULL;
if (T==NULL) /*插入 s 为新的根结点*/
{
T = s;
}
else
{/*查找插入位置*/
while(p && p->data!=e) /*如果当前节点不为空且节点的值不是插入的值 */
{
if (p->data>e)
{f=p; p=p->lchild;} /*如果当前节点值大于插入的值,则记录当前节点,并将节点的左节点作为当前节点 */
else
{f=p; p=p->rchild;} /*否则,节点的右节点作为当前节点 */
}
if (p==NULL&&e <f->data) /*如果当前节点为空并且插入的值小于父节点中的值; */
f->lchild = s; /*插入 s 为 f 的左孩子 */
else if(p==NULL&&e>f->data) f->rchild = s; /* 插入 s 为 f 的右孩子*/
else {printf("insert wrong!");exit(0);}
}
return T;
}
void Postorder(BiTree T)
{ /* 中序遍历二叉树 */
if (T)
{
Postorder(T->rchild); /* 遍历左子树 */
printf("%d ",T->data); /*访问结点 */
Postorder(T->lchild);/* 遍历右子树 */
}
}
void main()
{
int e,i;
BiTree T;
T=NULL;
printf("input 6 num:\n");
for(i=1;i <7;i++)
{
scanf("%d",&e);
T=Insert(T,e);
}
printf("Postorder:\n");
Postorder(T);
printf("\n");
getchar();
}
‘伍’ 如何用C语言实现层次遍历二叉树
下面是c语言的前序遍历二叉树的算法,在这里假设的节点元素值假设的为字符型,
说明:算法中用到了结构体,也用到了递归的方法,你看看怎么样,祝你好运!
#include"stdio.h"
typedef
char
elemtype;
typedef
struct
node
//定义链表结构
{
elemtype
data;
//定义节点值
struct
note
*lchild;
//定义左子节点值
struct
note
*rchild;
//定义右节点值
}btree;
preorder(btree
*root)
//前序遍历
{
if(roof!=null)
//如果不是空节点
{
printf("%c\n",root->data);
//输出当前节点
preorder(root->lchild);
//递归前序遍历左子节点
preorder(root->rchild);
//递归前序遍历右子节点
}
return;
//结束
}
‘陆’ 帮忙看一下这个C语言程序二叉排序 高校分数线查询
源程序:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define n 15
typedef int KeyType;
typedef char NameType;
typedef struct node{
KeyType key;
char name[n];
struct node *lchild,*rchild;
}BSTNode;
typedef BSTNode *BSTree;
BSTree CreateBST(void);
void SearchBST(BSTree T,KeyType Key);
void InsertBST(BSTree *Tptr,char *Name,KeyType Key);
void DelBSTNode(BSTree *Tptr,KeyType Key);
void InorderBST(BSTree T);
void BetweenSearchBST(BSTree T, KeyType Key1,KeyType Key2);
void LowSearchBST(BSTree T,KeyType Key);
main()
{
BSTree T;
char ch1,ch2;
KeyType Key;
KeyType Key1,Key2;
char *Name;
printf("建立高考各高校录取最低分数线查询表\n");
T=CreateBST();
ch1='y';
while (ch1=='y' || ch1=='Y')
{
printf("请选择下列操作:\n");
printf("1------------------更新高考各高校录取最低分数线查询表\n");
printf("2------------------查询等于给定分数线的高校\n");
printf("3------------------查询小于给定分数线的高校\n");
printf("4------------------查询在给定分数线段[Key1,Key2]中的所有高校.\n");
printf("5------------------插入一所高校的高考录取最低分数线\n");
printf("6------------------删除一所高校的高考录取最低分数线\n");
printf("7------------------输出高考各高校录取最低分数线查询表\n");
printf("8------------------ 退出\n");
scanf("\n%c",&ch2);
switch (ch2)
{
case '1': T=CreateBST();break;
case '2': printf("\n请输入要查询的分数:\n");
scanf("\n%d",&Key);
SearchBST(T,Key);
printf("\n查询操作完毕。\n");break;
case '3': printf("\n请输入要查询的分数:\n");
scanf("\n%d",&Key);
LowSearchBST(T,Key);
printf("\n查询操作完毕。\n");break;
case '4': printf("\n给定分数线段[Key1,Key2]:\n");
scanf("%d %d",&Key1,&Key2);
BetweenSearchBST(T,Key1,Key2);
printf("\n查询操作完毕。\n"); break;
case '5': printf("\n请输入要插入的高校名字:\n");
scanf("%s",Name);
printf("请输入要插入的高校的最低分数线:\n");
scanf("\n%d",&Key);
InsertBST(&T,Name,Key);
printf("\n插入操作完毕。\n");break;
case '6': printf("\n请输入要删除的分数线:\n");
scanf("\n%d",&Key);
DelBSTNode(&T,Key);
printf("\n删除操作完毕。\n");break;
case '7': InorderBST(T);
printf("\n分数线排序输出完毕。\n");break;
case '8': ch1='n';break;
default: ch1='n';
}
}
}
BSTree CreateBST(void)
{
BSTree T;
KeyType Key;
char *Name;
T=NULL;
printf("请输入一所高校的数据(输入两次0时结束输入):\n");
scanf("%s",Name);
scanf("%d",&Key);
while (Key)
{
InsertBST(&T,Name,Key);
printf("请输入下一所高校的数据(输入两次0时结束输入):\n");
scanf("%s",Name);
scanf("%d",&Key);
}
return T;
}
void SearchBST(BSTree T, KeyType Key)
{
BSTNode *p=T;
while(p)
{
if(p->key==Key)
{
printf("已找到\n");
printf("%s",p->name);
printf("%5d",p->key);
return;
}
p=(Key<p->key) ? p->lchild:p->rchild;
}
printf("没有找到\n");
}
void InsertBST(BSTree *T,char *Name,KeyType Key)
{
BSTNode *f,*p;int k;
p=(*T);
while(p)
{ k=strcmp(p->name,Name);
if(k==0)
{
printf("表中已有该高校不需插入\n");
return;
}
f=p;
p=(Key<p->key)?p->lchild:p->rchild;
}
p=(BSTNode*)malloc(sizeof(BSTNode));
strcpy(p->name,Name);
p->key=Key;
p->lchild=p->rchild=NULL;
if ((*T)==NULL) (*T)=p;
else if (Key<f->key) f->lchild=p;
else f->rchild=p;
}
void DelBSTNode(BSTree *T,KeyType Key)
{
BSTNode *parent=NULL, *p, *q,*child;
p=*T;
while(p)
{
if(p->key==Key) break;
parent=p;
p=(Key<p->key)?p->lchild:p->rchild;
}
if (!p) {printf("没有找到要删除的高校\n");return;}
q=p;
if (q->lchild && q->rchild)
for (parent=q,p=q->rchild; p->lchild; parent=p,p=p->lchild);
child=(p->lchild)?p->lchild:p->rchild;
if (!parent) *T=child;
else
{
if (p==parent->lchild)
parent->lchild=child;
else parent->rchild=child;
if (p!=q)
q->key=p->key;
}
free(p);
}
void InorderBST(BSTree T)
{
if(T!=NULL)
{
InorderBST(T->lchild);
printf("%s",T->name);
printf("%8d\n",T->key);
InorderBST(T->rchild);
}
}
void BetweenSearchBST(BSTree T, KeyType Key1,KeyType Key2)
{
BSTNode *p=T;
if(p)
{
if(p->key<Key2&&p->key>Key1)
{
printf("已找到\n");
printf("%s",p->name);
printf("%8d\n",p->key);
}
if(Key1>=p->key)p=p->lchild;
BetweenSearchBST(T->lchild,Key1,Key2);
if(Key2<=p->key)p=p->rchild;
BetweenSearchBST(T->rchild,Key1,Key2);
}
return;
}
void LowSearchBST(BSTree T, KeyType Key)
{
BSTNode *p=T;
if(p)
{
if(p->key<Key)
{
printf("已找到\n");
printf("%s",p->name);
printf("%8d\n",p->key);
}
LowSearchBST(p->lchild,Key);
LowSearchBST(p->rchild,Key);
}
else
return;
}
‘柒’ c语言二叉树问题求解~
#include"stdio.h"
intposition(int,int);
intmain(intargc,charconst*argv[])
{
intp,q,pos,times;
printf("请输入数组的组数:");
scanf("%d",×);
while(times>0)
{
printf("请输入p,q:");
scanf("%d%d",&p,&q);
pos=position(p,q);
printf("%d ",pos);
times--;
}
return0;
}
intposition(intp,intq)
{
//printf("%d%d ",p,q);//这个可以看到过程
if(p==q)return1;
if(p>q)//右子树
{
return2*position(p-q,q)+1;
}else//左子树
{
return2*position(p,q-p);
}
}
//在主函数中调用position,可以得到相应地位置,简单的验证过,应该是正确的
//这个基本上涉及到了二叉查找树,子节点和父节点索引的关系:2N,2N+1
//基本算法就是这样了,至于按你的要求输入多组数据,可以自己做了
‘捌’ 急急,设计一个“二叉”查找算法,将集合分成1/3和2/3大小的两个集合
这个问题很简单,排序,然后找到分割点,分。
就这样。你说什么二叉查找算法,是不是说要对已经排序好的二叉树进行分割?
题目也表达的比较乱。
‘玖’ 二叉查找树算法
#include <iostream>using namespace std;typedef struct _node{ int data; struct _node *pLeftPtr; struct _node *pRightPtr;}BTreeNode;class BinarySearchTree{public: BinarySearchTree(); ~BinarySearchTree(); bool Create(int* pIntArray,int arrLength); bool Insert(int data); // 查找节点,searchLength为搜索长度,返回值为true表示指定的数据存在,否则不存在 bool Find(int data, int* searchLength); // 中序输出二叉树 void MidOutput(); // 释放内存 void Destroy(); void Delete(int data);protected: bool Insert(BTreeNode* pRoot, int data); bool Find(BTreeNode* pRoot,int data, int *searchLength); void Delete(BTreeNode* &pRoot, int data); void MidOutput(BTreeNode* pRoot); void Destroy(BTreeNode* pRoot);private: BTreeNode* m_pRoot; //二叉搜索树根节点};BinarySearchTree::BinarySearchTree(){ m_pRoot = NULL;}BinarySearchTree::~BinarySearchTree(){ Destroy();}bool BinarySearchTree::Create(int* pIntArray,int arrLength){ for(int i=0; i<arrLength; i++) { if(!Insert(*(pIntArray+i))) return false; } return true;}bool BinarySearchTree::Insert(BTreeNode* pRoot, int data){ BTreeNode* pNewNode = new BTreeNode; if(pNewNode == NULL) return false; pNewNode->data = data; pNewNode->pLeftPtr = NULL; pNewNode->pRightPtr = NULL; BTreeNode* pCurrentNode = pRoot; BTreeNode* pParentNode = pCurrentNode;// 保存父节点的指针 int flag = 0;// 标记插入节点的位置 if(pCurrentNode == NULL) { m_pRoot = pNewNode; }else{ while(pCurrentNode) { if(data < pCurrentNode->data) { pParentNode = pCurrentNode; pCurrentNode = pCurrentNode->pLeftPtr; flag = 0; }else if(data > pCurrentNode->data){ pParentNode = pCurrentNode; pCurrentNode = pCurrentNode->pRightPtr; flag = 1; } } if(flag == 0) { pParentNode->pLeftPtr = pNewNode; }else{ pParentNode->pRightPtr = pNewNode; } } return true; }bool BinarySearchTree::Insert(int data){ return Insert(m_pRoot,data);}bool BinarySearchTree::Find(BTreeNode* pRoot,int data, int *searchLength){ if(pRoot == NULL) { *searchLength = 0; return false; } BTreeNode* pCurrentNode = pRoot; static int length = 0; while(pCurrentNode != NULL) { if(data == pCurrentNode->data) { *searchLength = length; cout<<"数字"<<data<<"存在二叉树中,查找长度为: "<<endl<<length<<endl; return true; }else if(data < pCurrentNode->data) { length ++; pCurrentNode = pCurrentNode->pLeftPtr; }else{ length ++; pCurrentNode = pCurrentNode->pRightPtr; } } *searchLength = length; cout<<"数字"<<data<<"不在二叉树中,查找长度为: "<<endl<<length<<endl; length = 0; // 每次查找结束,重新赋值为0 return false;}bool BinarySearchTree::Find(int data, int* searchLength){ return Find(m_pRoot,data,searchLength);}void BinarySearchTree::Destroy(BTreeNode* pRoot){ BTreeNode* pCurrentNode = pRoot; if(pCurrentNode == NULL) return; Destroy(pCurrentNode->pLeftPtr); Destroy(pCurrentNode->pRightPtr); delete pCurrentNode; m_pRoot = NULL;}void BinarySearchTree::Destroy(){ Destroy(m_pRoot);}void BinarySearchTree::MidOutput(BTreeNode* pRoot){ if(pRoot) { MidOutput(pRoot->pLeftPtr); cout<<pRoot->data <<" "; MidOutput(pRoot->pRightPtr); }}void BinarySearchTree::MidOutput(){ MidOutput(m_pRoot);}void BinarySearchTree::Delete(int data){ Delete(m_pRoot,data);}void BinarySearchTree::Delete(BTreeNode* &pRoot, int data){ if(!pRoot) return; else if(data == pRoot->data){ if(pRoot->pLeftPtr == NULL && pRoot->pRightPtr == NULL) // 叶子节点 { delete pRoot; pRoot = NULL; }else if(pRoot->pLeftPtr != NULL && pRoot->pRightPtr == NULL){ // 只有左子树 BTreeNode* pNode = pRoot->pLeftPtr; delete pRoot; pRoot = pNode; }else if(pRoot->pLeftPtr == NULL && pRoot->pRightPtr != NULL){ // 只有右子树 BTreeNode* pNode = pRoot->pRightPtr; delete pRoot; pRoot = pNode; }else{ // 有左右子树 // 找到左子树的最大节点 BTreeNode* pCurrentNode = pRoot->pLeftPtr; BTreeNode* pParentNode = NULL; while(pCurrentNode->pRightPtr != NULL) { pParentNode = pCurrentNode; pCurrentNode = pCurrentNode->pRightPtr; } pRoot->data = pCurrentNode->data; if(pParentNode) { pParentNode->pRightPtr = pCurrentNode->pLeftPtr; }else{ pRoot->pLeftPtr= pCurrentNode->pLeftPtr; } delete pCurrentNode; } }else if(data < pRoot->data) Delete(pRoot->pLeftPtr, data); else Delete(pRoot->pRightPtr, data);}void main(){ int data[8]; cout<<"请输入整形数据, 数据用空格隔开, 回车键结束输入"<<endl; for(int i=0; i<8; i++) cin>>data[i]; // int data[8] = {13,15,6,20,14,5,7,18}; BinarySearchTree tree; tree.Create(data,sizeof(data)/sizeof(data[0])); cout<<"插入数据后的二叉树为: "<<endl; tree.MidOutput(); cout<<endl; int len_1=0; int len_2=0; tree.Find(14,&len_1); tree.Find(21,&len_2); tree.Delete(20); cout<<"删除数字20后的二叉树结果: "<<endl; tree.MidOutput(); cout<<endl; tree.Delete(15); cout<<"删除数字15后的二叉树结果: "<<endl; tree.MidOutput(); cout<<endl;}
‘拾’ 求用C语言实现二叉树层次遍历的递归算法,谢谢!!!
算法思想:层次遍历目前最普遍用的就是队列的那种方式,不是递归,但是用到while循环,既然题目要求用递归,可以用递归实现该while循环功能。算法如下:
void TransLevele(Tree *r)
{
if (r==NULL)
{
return ;
}
printf("%c",r->ch);
if (r->left != NULL)
{
InsertQueue(r->left);
}
if (r->right != NULL)
{
InsertQueue(r->right);
}
Tree *t = DeleteQueue();
TransLevele(t);
}
//测试程序,创建树输入例如ABD##E##C##,根左右创建的方式。
如下代码是测试通过的。
#include "stdlib.h"
#define MAX 100
typedef int Element;
typedef struct tree
{
Element ch;
struct tree *left;
struct tree *right;
}Tree;
typedef struct queue
{
Tree *a[MAX];
int front;
int rear;
}Queue;
Queue Qu;
void Init();
int InsertQueue(Element ch);
Tree *DeleteQueue();
void CreateTree(Tree **r);
void TransLevele(Tree *r);
void PrintTree(Tree *r);
int main()
{
Tree *r=NULL;
CreateTree(&r);
PrintTree(r);
printf("\n");
TransLevele(r);
return 0;
}
void Init()
{
int i=0;
for (i=0; i<MAX; i++)
{
Qu.a[i] = NULL;
}
Qu.front = 0;
Qu.rear = 0;
}
int InsertQueue(Tree *r)
{
if ( (Qu.rear+1)%MAX == Qu.front)
{
printf("Queue full!");
return 0;
}
Qu.a[Qu.rear] = r;
Qu.rear = (Qu.rear+1)%MAX;
return 1;
}
Tree *DeleteQueue()
{
if (Qu.front == Qu.rear)
{
printf("Queue empty");
return NULL;
}
Tree *t=NULL;
t = Qu.a[Qu.front];
Qu.front = (Qu.front+1)%MAX;
return t;
}
void CreateTree(Tree **r)
{
Element ch;
ch=getchar();
if (ch=='#')
{
(*r)=NULL;
return ;
}
*r = (Tree *)malloc(sizeof(Tree));
(*r)->ch = ch;
CreateTree(&((*r)->left));
CreateTree(&((*r)->right));
}
void PrintTree(Tree *r)
{
if (r==NULL)
{
return ;
}
printf("%c",r->ch);
PrintTree(r->left);
PrintTree(r->right);
}
void TransLevele(Tree *r)
{
if (r==NULL)
{
return ;
}
printf("%c",r->ch);
if (r->left != NULL)
{
InsertQueue(r->left);
}
if (r->right != NULL)
{
InsertQueue(r->right);
}
Tree *t = DeleteQueue();
TransLevele(t);
}