用扩展先序创建二叉链表
来源:互联网 发布:ipadmini1实用软件 编辑:程序博客网 时间:2024/05/16 12:06
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
char date;
struct Node *lchild;
struct Node *rchild;
}node;
void inlist(node *&l)//取L得地址
{
char ch;
ch=getchar();
if(ch=='.')
l=NULL;
else
{
l=(node *)malloc(sizeof(node));
l->date=ch;
inlist(l->lchild);
inlist(l->rchild);
}
}
void prelist3(node *&l)//先序遍历二叉树
{
node *root;
root=l;
if(root!=NULL)
{
if(root->lchild==NULL&&root->rchild==NULL)//输出叶子结点
printf("%c",root->date);
prelist3(root->lchild);
prelist3(root->rchild);
}
}
void prelist1(node *&l)//中遍历二叉树
{
node *root;
root=l;
if(root!=NULL)
{
prelist1(root->lchild);
printf("%c",root->date);
prelist1(root->rchild);
}
}
void prelist2(node *&l)//后序遍历二叉树
{
node *root;
root=l;
if(root!=NULL)
{
prelist2(root->lchild);
prelist2(root->rchild);
printf("%c",root->date);
}
}
int main()
{
node *l;
inlist(l);
prelist3(l);
printf("\n");
prelist1(l);
printf("\n");
prelist2(l);
printf("\n");
return 0;
}
#include<stdlib.h>
typedef struct Node
{
char date;
struct Node *lchild;
struct Node *rchild;
}node;
void inlist(node *&l)//取L得地址
{
char ch;
ch=getchar();
if(ch=='.')
l=NULL;
else
{
l=(node *)malloc(sizeof(node));
l->date=ch;
inlist(l->lchild);
inlist(l->rchild);
}
}
void prelist3(node *&l)//先序遍历二叉树
{
node *root;
root=l;
if(root!=NULL)
{
if(root->lchild==NULL&&root->rchild==NULL)//输出叶子结点
printf("%c",root->date);
prelist3(root->lchild);
prelist3(root->rchild);
}
}
void prelist1(node *&l)//中遍历二叉树
{
node *root;
root=l;
if(root!=NULL)
{
prelist1(root->lchild);
printf("%c",root->date);
prelist1(root->rchild);
}
}
void prelist2(node *&l)//后序遍历二叉树
{
node *root;
root=l;
if(root!=NULL)
{
prelist2(root->lchild);
prelist2(root->rchild);
printf("%c",root->date);
}
}
int main()
{
node *l;
inlist(l);
prelist3(l);
printf("\n");
prelist1(l);
printf("\n");
prelist2(l);
printf("\n");
return 0;
}
0 0
- 用扩展先序创建二叉链表
- 数据结构复习(先序创建链表二叉树)
- 先序创建二叉树
- 递归创建先序序列二叉树
- 创建二叉树,并先序遍历
- java先序递归创建二叉树
- java 二叉树/创建/先序/中序/后序
- 先序遍历和中序遍历创建二叉树
- 先序遍历/后序遍历创建线索二叉树
- 已知先序序列、中序序列创建二叉树
- 二叉树的先序创建和遍历
- #法(先序遍历)创建二叉树
- 【数据结构】扩充先序遍历创建二叉树
- 先序创建二叉树及三种遍历
- 二叉树的先序递归创建和遍历
- 二叉树的创建和先序遍历
- 判断平衡二叉树,创建二叉树,先序遍历二叉树
- 用二叉链表存储的二叉树进行先序、中序和后序遍历的算法
- hahahahah
- js逗号运算符
- 仿站的流程
- html5新属性,事件,API方法 笔记1.
- dsadsads
- 用扩展先序创建二叉链表
- 1.从一个问题开始
- HTML 5 APP 与原生 APP的差距到底在哪
- SQL server 添加主外键约束
- UVa 12563_Jin Ge Jin Qu hao
- 开源GIS系统介绍
- 黑马程序员----java面向对象
- 2.进程和线程的结构是什么?
- 关于活动的一些小技巧