问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

求数据结构 二叉树的基本操作实现 c语言版

发布网友 发布时间:2022-04-29 18:14

我来回答

1个回答

热心网友 时间:2023-10-29 21:13

# include <stdio.h>

# include <malloc.h>

struct BTNode

{

int data;

struct BTNode * pLchild;//p是指针,L是左,child是孩子

struct BTNode * pRchild;

};

//函数声明

struct BTNode * CreateBTree(void);//创建树

void PreTraverseBTree(struct BTNode * pT);//先序遍历

void InTraverseBTree(struct BTNode * pT);//中序遍历

void PostTraverseBTree(struct BTNode * pT);//后续遍历

int main(void)

{

struct BTNode * pT = CreateBTree();

PreTraverseBTree(pT);

printf("\n");

InTraverseBTree(pT);

printf("\n");

PostTraverseBTree(pT);

return 0;

}

//创建树

struct BTNode * CreateBTree(void)

{

struct BTNode * pA = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pB = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pC = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pD = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pE = (struct BTNode * )malloc(sizeof(BTNode));

pA->data = 'A';

pB->data = 'B';

pC->data = 'C';

pD->data = 'D';

pE->data = 'E';

pA->pLchild = pB;

pA->pRchild = pC;

pB->pLchild = NULL;

pB->pRchild = NULL;

pC->pLchild = pD;

pC->pRchild = NULL;

pD->pLchild = NULL;

pD->pRchild = pE;

pE->pLchild = NULL;

pE->pRchild = NULL;

return pA;

}

//先序遍历

void PreTraverseBTree(struct BTNode * pT)

{ //先访问根节点,再先序访问左子树,最后先序访问右子树

if ( pT != NULL)

{

printf("%c\n",pT->data);//访问根节点

//pT->pLchild可以代表整个左子树

PreTraverseBTree(pT->pLchild);

PreTraverseBTree(pT->pRchild);

}

return;

}

//中序遍历

void InTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

InTraverseBTree(pT->pLchild);

}

printf("%c\n",pT->data);

if (NULL != pT->pRchild)

{

InTraverseBTree(pT->pRchild);

}

}

return;

}

//后续遍历

void PostTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

PostTraverseBTree(pT->pLchild);

}

if (NULL != pT->pRchild)

{

PostTraverseBTree(pT->pRchild);

}

printf("%c\n",pT->data);

}

return;

}

热心网友 时间:2023-10-29 21:13

# include <stdio.h>

# include <malloc.h>

struct BTNode

{

int data;

struct BTNode * pLchild;//p是指针,L是左,child是孩子

struct BTNode * pRchild;

};

//函数声明

struct BTNode * CreateBTree(void);//创建树

void PreTraverseBTree(struct BTNode * pT);//先序遍历

void InTraverseBTree(struct BTNode * pT);//中序遍历

void PostTraverseBTree(struct BTNode * pT);//后续遍历

int main(void)

{

struct BTNode * pT = CreateBTree();

PreTraverseBTree(pT);

printf("\n");

InTraverseBTree(pT);

printf("\n");

PostTraverseBTree(pT);

return 0;

}

//创建树

struct BTNode * CreateBTree(void)

{

struct BTNode * pA = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pB = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pC = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pD = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pE = (struct BTNode * )malloc(sizeof(BTNode));

pA->data = 'A';

pB->data = 'B';

pC->data = 'C';

pD->data = 'D';

pE->data = 'E';

pA->pLchild = pB;

pA->pRchild = pC;

pB->pLchild = NULL;

pB->pRchild = NULL;

pC->pLchild = pD;

pC->pRchild = NULL;

pD->pLchild = NULL;

pD->pRchild = pE;

pE->pLchild = NULL;

pE->pRchild = NULL;

return pA;

}

//先序遍历

void PreTraverseBTree(struct BTNode * pT)

{ //先访问根节点,再先序访问左子树,最后先序访问右子树

if ( pT != NULL)

{

printf("%c\n",pT->data);//访问根节点

//pT->pLchild可以代表整个左子树

PreTraverseBTree(pT->pLchild);

PreTraverseBTree(pT->pRchild);

}

return;

}

//中序遍历

void InTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

InTraverseBTree(pT->pLchild);

}

printf("%c\n",pT->data);

if (NULL != pT->pRchild)

{

InTraverseBTree(pT->pRchild);

}

}

return;

}

//后续遍历

void PostTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

PostTraverseBTree(pT->pLchild);

}

if (NULL != pT->pRchild)

{

PostTraverseBTree(pT->pRchild);

}

printf("%c\n",pT->data);

}

return;

}

热心网友 时间:2023-10-29 21:13

# include <stdio.h>

# include <malloc.h>

struct BTNode

{

int data;

struct BTNode * pLchild;//p是指针,L是左,child是孩子

struct BTNode * pRchild;

};

//函数声明

struct BTNode * CreateBTree(void);//创建树

void PreTraverseBTree(struct BTNode * pT);//先序遍历

void InTraverseBTree(struct BTNode * pT);//中序遍历

void PostTraverseBTree(struct BTNode * pT);//后续遍历

int main(void)

{

struct BTNode * pT = CreateBTree();

PreTraverseBTree(pT);

printf("\n");

InTraverseBTree(pT);

printf("\n");

PostTraverseBTree(pT);

return 0;

}

//创建树

struct BTNode * CreateBTree(void)

{

struct BTNode * pA = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pB = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pC = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pD = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pE = (struct BTNode * )malloc(sizeof(BTNode));

pA->data = 'A';

pB->data = 'B';

pC->data = 'C';

pD->data = 'D';

pE->data = 'E';

pA->pLchild = pB;

pA->pRchild = pC;

pB->pLchild = NULL;

pB->pRchild = NULL;

pC->pLchild = pD;

pC->pRchild = NULL;

pD->pLchild = NULL;

pD->pRchild = pE;

pE->pLchild = NULL;

pE->pRchild = NULL;

return pA;

}

//先序遍历

void PreTraverseBTree(struct BTNode * pT)

{ //先访问根节点,再先序访问左子树,最后先序访问右子树

if ( pT != NULL)

{

printf("%c\n",pT->data);//访问根节点

//pT->pLchild可以代表整个左子树

PreTraverseBTree(pT->pLchild);

PreTraverseBTree(pT->pRchild);

}

return;

}

//中序遍历

void InTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

InTraverseBTree(pT->pLchild);

}

printf("%c\n",pT->data);

if (NULL != pT->pRchild)

{

InTraverseBTree(pT->pRchild);

}

}

return;

}

//后续遍历

void PostTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

PostTraverseBTree(pT->pLchild);

}

if (NULL != pT->pRchild)

{

PostTraverseBTree(pT->pRchild);

}

printf("%c\n",pT->data);

}

return;

}

热心网友 时间:2023-10-29 21:13

# include <stdio.h>

# include <malloc.h>

struct BTNode

{

int data;

struct BTNode * pLchild;//p是指针,L是左,child是孩子

struct BTNode * pRchild;

};

//函数声明

struct BTNode * CreateBTree(void);//创建树

void PreTraverseBTree(struct BTNode * pT);//先序遍历

void InTraverseBTree(struct BTNode * pT);//中序遍历

void PostTraverseBTree(struct BTNode * pT);//后续遍历

int main(void)

{

struct BTNode * pT = CreateBTree();

PreTraverseBTree(pT);

printf("\n");

InTraverseBTree(pT);

printf("\n");

PostTraverseBTree(pT);

return 0;

}

//创建树

struct BTNode * CreateBTree(void)

{

struct BTNode * pA = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pB = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pC = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pD = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pE = (struct BTNode * )malloc(sizeof(BTNode));

pA->data = 'A';

pB->data = 'B';

pC->data = 'C';

pD->data = 'D';

pE->data = 'E';

pA->pLchild = pB;

pA->pRchild = pC;

pB->pLchild = NULL;

pB->pRchild = NULL;

pC->pLchild = pD;

pC->pRchild = NULL;

pD->pLchild = NULL;

pD->pRchild = pE;

pE->pLchild = NULL;

pE->pRchild = NULL;

return pA;

}

//先序遍历

void PreTraverseBTree(struct BTNode * pT)

{ //先访问根节点,再先序访问左子树,最后先序访问右子树

if ( pT != NULL)

{

printf("%c\n",pT->data);//访问根节点

//pT->pLchild可以代表整个左子树

PreTraverseBTree(pT->pLchild);

PreTraverseBTree(pT->pRchild);

}

return;

}

//中序遍历

void InTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

InTraverseBTree(pT->pLchild);

}

printf("%c\n",pT->data);

if (NULL != pT->pRchild)

{

InTraverseBTree(pT->pRchild);

}

}

return;

}

//后续遍历

void PostTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

PostTraverseBTree(pT->pLchild);

}

if (NULL != pT->pRchild)

{

PostTraverseBTree(pT->pRchild);

}

printf("%c\n",pT->data);

}

return;

}

热心网友 时间:2023-10-29 21:13

# include <stdio.h>

# include <malloc.h>

struct BTNode

{

int data;

struct BTNode * pLchild;//p是指针,L是左,child是孩子

struct BTNode * pRchild;

};

//函数声明

struct BTNode * CreateBTree(void);//创建树

void PreTraverseBTree(struct BTNode * pT);//先序遍历

void InTraverseBTree(struct BTNode * pT);//中序遍历

void PostTraverseBTree(struct BTNode * pT);//后续遍历

int main(void)

{

struct BTNode * pT = CreateBTree();

PreTraverseBTree(pT);

printf("\n");

InTraverseBTree(pT);

printf("\n");

PostTraverseBTree(pT);

return 0;

}

//创建树

struct BTNode * CreateBTree(void)

{

struct BTNode * pA = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pB = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pC = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pD = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pE = (struct BTNode * )malloc(sizeof(BTNode));

pA->data = 'A';

pB->data = 'B';

pC->data = 'C';

pD->data = 'D';

pE->data = 'E';

pA->pLchild = pB;

pA->pRchild = pC;

pB->pLchild = NULL;

pB->pRchild = NULL;

pC->pLchild = pD;

pC->pRchild = NULL;

pD->pLchild = NULL;

pD->pRchild = pE;

pE->pLchild = NULL;

pE->pRchild = NULL;

return pA;

}

//先序遍历

void PreTraverseBTree(struct BTNode * pT)

{ //先访问根节点,再先序访问左子树,最后先序访问右子树

if ( pT != NULL)

{

printf("%c\n",pT->data);//访问根节点

//pT->pLchild可以代表整个左子树

PreTraverseBTree(pT->pLchild);

PreTraverseBTree(pT->pRchild);

}

return;

}

//中序遍历

void InTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

InTraverseBTree(pT->pLchild);

}

printf("%c\n",pT->data);

if (NULL != pT->pRchild)

{

InTraverseBTree(pT->pRchild);

}

}

return;

}

//后续遍历

void PostTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

PostTraverseBTree(pT->pLchild);

}

if (NULL != pT->pRchild)

{

PostTraverseBTree(pT->pRchild);

}

printf("%c\n",pT->data);

}

return;

}

热心网友 时间:2023-10-29 21:13

# include <stdio.h>

# include <malloc.h>

struct BTNode

{

int data;

struct BTNode * pLchild;//p是指针,L是左,child是孩子

struct BTNode * pRchild;

};

//函数声明

struct BTNode * CreateBTree(void);//创建树

void PreTraverseBTree(struct BTNode * pT);//先序遍历

void InTraverseBTree(struct BTNode * pT);//中序遍历

void PostTraverseBTree(struct BTNode * pT);//后续遍历

int main(void)

{

struct BTNode * pT = CreateBTree();

PreTraverseBTree(pT);

printf("\n");

InTraverseBTree(pT);

printf("\n");

PostTraverseBTree(pT);

return 0;

}

//创建树

struct BTNode * CreateBTree(void)

{

struct BTNode * pA = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pB = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pC = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pD = (struct BTNode * )malloc(sizeof(BTNode));

struct BTNode * pE = (struct BTNode * )malloc(sizeof(BTNode));

pA->data = 'A';

pB->data = 'B';

pC->data = 'C';

pD->data = 'D';

pE->data = 'E';

pA->pLchild = pB;

pA->pRchild = pC;

pB->pLchild = NULL;

pB->pRchild = NULL;

pC->pLchild = pD;

pC->pRchild = NULL;

pD->pLchild = NULL;

pD->pRchild = pE;

pE->pLchild = NULL;

pE->pRchild = NULL;

return pA;

}

//先序遍历

void PreTraverseBTree(struct BTNode * pT)

{ //先访问根节点,再先序访问左子树,最后先序访问右子树

if ( pT != NULL)

{

printf("%c\n",pT->data);//访问根节点

//pT->pLchild可以代表整个左子树

PreTraverseBTree(pT->pLchild);

PreTraverseBTree(pT->pRchild);

}

return;

}

//中序遍历

void InTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

InTraverseBTree(pT->pLchild);

}

printf("%c\n",pT->data);

if (NULL != pT->pRchild)

{

InTraverseBTree(pT->pRchild);

}

}

return;

}

//后续遍历

void PostTraverseBTree(struct BTNode * pT)

{

if(pT != NULL )

{

if (NULL != pT->pLchild)

{

PostTraverseBTree(pT->pLchild);

}

if (NULL != pT->pRchild)

{

PostTraverseBTree(pT->pRchild);

}

printf("%c\n",pT->data);

}

return;

}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
太平盛世专辑曲目 梦见自家灶台缺个角 如何看待宝马3系? - 知乎 为什么缺爱的女人婚姻难幸福快乐 求一些好看的架空言情小说,最好是以第一人称为视角的。小白文请绕。 带双目相机的无人机有哪些 禄莱1982年后 工业3d相机国内有哪些靠谱的厂商,特别是在阳光和弱光环境 海康全新双目单线相机 | 消盲区、抑杂光,引领3D检测新突破 10米范围内实现零盲区大FoV深度测量,奥比中光发布Gemini 2双目... 云缴费交灵活就业社保靠谱吗? 工商银行开户30000和保险投保-3万是什么意思 二叉树基本操作设计及实现 二叉树的建立及基本操作 工商银行一年存一万存五年还送保险是什么业务 私募基金从业资格证要从事公募基金需要重新考试吗 蚂蚁金服开发平台可以独立使用吗 请问下,私募基金从业人员需要什么资格证,具体参加哪些科目的考试? 如何选购好你的主板? 用云缴费交社保靠谱吗? 做私募的话,证券从业人员资格考试考哪几门? 隽星主版有那些优点 光大云缴费的养老保险靠谱吗? 请问我怎么了解蚂蚁金服是什么东西?蚂蚁金服备用金是什么意思? 如何辨别电脑主板的高端产品和低端 从哪里看出 我家的CUP外面写有 lotes socket AMS ,请问这是什么类型的CUP?是双核么?什么型号的?求大神告知。 在宁波想要从事私募基金需要考哪科? 前端框架是做什么的,是否需要把所有的都了解一下呢? 115xlm主板上什么cpu 去私募公司做操盘手需要考什么证书,是必须考的? 我之前交的养老保险都是在河北税务局交的,这次从云缴费里交的,显示商户在光大银行,有什么影响吗? 二叉树的基本操作实现(c++版) 通过工行个人网上银行投保有哪些方式支付保费? 云缴费怎么交养老保险 数据结构:用栈的5种基本操作实现二叉树的遍历 在两个透支卡之间来回倒钱,来维持一个欠款的卡,这样做有问题么?违法么? 我在工商银行定期存款,为什么被扣了三万说是投保了 办信用卡,怎么工作包装会合适一些。 华为mate40pro关机情况下电量低于百分之8 遍历二叉树的实现(C语言)帮忙啊... 谁知道办理信用卡怎么包装单位呢。 二叉树的存储及遍历的基本操作及 C 语言实现 用c语言写二叉排序树的基本操作要求实现查找插入和删除运算,统计二叉... 在云缴费上交完养老保险怎么查不到 去工商银行存定期却被推销了安邦共赢3号投资型综合保险(火灾家庭财产保险)这到底是什么东东? 申请信用卡如何包装下卡快?详细点,谢谢 办两张信用卡怎么倒钱 办信用卡怎么包装自己 俩张信用卡如何来回倒? 个人信用卡申请资料怎么包装