云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 二叉树的基本操作

二叉树的基本操作

  • 62 次阅读
  • 3 次下载
  • 2026/4/26 5:28:43

/*

************************************************ *Name : Bittree all operation *Date : 2014-12-18 *Author : marksman

*Aim : Create a bittree and visit it.

************************************************ */

#include #include /*

*Tree structure */

typedef struct {

char date;

struct tree *lchild,*rchild; }tree,*Bit_tree; /*

*Create the bittree */

Bit_tree Create_bit_tree(Bit_tree bittree) {

char ch;

scanf(\ getchar(); if(ch=='$')

bittree = NULL; else {

bittree = (tree *)malloc(sizeof(tree)); bittree->date = ch;

bittree->lchild = Create_bit_tree(bittree->lchild); bittree->rchild = Create_bit_tree(bittree->rchild); }

return bittree; } /*

*preorder the bittree */

int preorder_bit_tree(Bit_tree bittree) {

if(bittree) {

printf(\

preorder_bit_tree(bittree->lchild); preorder_bit_tree(bittree->rchild); }

return 0; } /*

*inorder the bittree */

int inorder_bit_tree(Bit_tree bittree) {

if(bittree!=NULL) {

inorder_bit_tree(bittree->lchild); printf(\

inorder_bit_tree(bittree->rchild); }

return 0; } /*

*beorder the bittree */

int beorder_bit_tree(Bit_tree bittree) {

if(bittree!=NULL) {

beorder_bit_tree(bittree->lchild); beorder_bit_tree(bittree->rchild); printf(\ }

return 0; }

int main() {

Bit_tree bittree;

bittree = (tree *)malloc(sizeof(tree)); bittree = Create_bit_tree(bittree); preorder_bit_tree(bittree); printf(\

inorder_bit_tree(bittree); printf(\

beorder_bit_tree(bittree); printf(\ return 0; }

提供一组测试用例: A B C $ $ D E $ G $ $ F $ $ $

输出结果:

搜索更多关于: 二叉树的基本操作 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

/* ************************************************ *Name : Bittree all operation *Date : 2014-12-18 *Author : marksman *Aim : Create a bittree and visit it. ************************************************ */ #include #include /* *Tree structure */ typedef struct { char date; struct tree *lchild,*rchil

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com