二叉树的遍历
来源:互联网 发布:java课程多少钱 编辑:程序博客网 时间:2024/04/20 10:37
#include <stdio.h>
#include <stdlib.h>
typedef struct tree_node
{
char data;
struct tree_node *lchild,*rchild;
}BT_Node;
BT_Node *tree;
BT_Node * Creat_BTree(BT_Node *tree)
{
char ch;
ch=getchar();
if(ch == '*')
{
tree=NULL;
}
else
{
tree=(BT_Node*)malloc(sizeof(BT_Node));
tree->data=ch;
tree->lchild=Creat_BTree(tree->lchild);
tree->rchild=Creat_BTree(tree->rchild);
}
return tree;
}
void Visit_Node(BT_Node *tree)
{
printf(" ");
putchar(tree->data);
printf("\t");
}
void Pre_Order(BT_Node *tree)
{
if(!tree)
{
return ;
}
else
{
Visit_Node(tree);
Pre_Order(tree->lchild);
Pre_Order(tree->rchild);
}
}
void Mid_Order(BT_Node *tree)
{
if(!tree)
{
return ;
}
else
{
Mid_Order(tree->lchild);
Visit_Node(tree);
Mid_Order(tree->rchild);
}
}
void After_Order(BT_Node *tree)
{
if(!tree)
{
return ;
}
else
{
After_Order(tree->lchild);
Visit_Node(tree);
After_Order(tree->rchild);
}
}
int main(void)
{
printf("请输入树结点:\n");
tree=Creat_BTree(tree);
if(tree)
{
printf("\n前序遍历:\n");
Pre_Order(tree);
printf("\n");
printf("\n中序遍历:\n");
Mid_Order(tree);
printf("\n");
printf("\n后序遍历:\n");
After_Order(tree);
printf("\n");
}
return 0;
}
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- java中各种日期类型转换
- Oracle修改有规则的序列
- Java中有关剪切板的操作
- C#中Split用法
- 处理第三方模块的数据
- 二叉树的遍历
- 新浪开放平台---用code获取access_token(oauth2)
- flash存储中各量级对应的十六进制数
- Android系统内置的桌面图标 链接 网址
- QT Socket编程--UDP Server
- 百度之星之E:C++ 与Java
- Android requires compiler compliance level 5.0. Please fix project properties.错误
- 高斯告诉我们
- eclipse .java文件中按alt+/没有提示信息