• 2024-07-29数据结构----树
    目录树1.概念:1.1关于树的一些基本概念2. 二叉树2.1概念2.2二叉树性质(重点)2.3满二叉树、完全二叉树2.4二叉树的顺序存储结构2.5二叉树的遍历(重点)2.6二叉树的链式存储树1.概念:树(Tree)是(n>=0)个节点的有限集合T,它满足两个条件:有且仅有一个特定的
  • 2024-02-22【数据结构】C语言实现二叉树的相关操作
    树定义树(Tree)是n(n>=0)个结点的有限集若n==0,称为空树若n>0,则它满足如下两个条件:有且仅有一个特定的称为根(Root)的结点其余结点可分为m(m>=0)个互不相交的有限集T1,T2,T3,...Tm,其中每一个集合本身又是一棵树,称为根的子树(SubTree)术语结点:数据元素结点的度:结点
  • 2023-12-212023年10月20日
    二叉树的链式结构二叉树的数据结构:typedefstructNode{chardata;structNode*lchild,*rchild;}*Bitree,BiNode;分别为根,左孩子,右孩子二叉树的创建,先序遍历的方式如输入 “AB#CD###E#F##”voidcreatBitree(Bitree&T){charch;cin>>ch;if(ch=='#')T=NULL;else{T=newBi
  • 2023-12-16C语言 层次遍历二叉树
    代码如下#include<stdio.h>#include<stdlib.h>#defineMax_Size50typedefstructbitree{chardata;intlevel;structbitree*lchild;structbitree*rchild;}BiTreeNode,*BiTree;typedefstructqueue{BiTreeData[Max_Size];
  • 2023-12-05二叉树创建及遍历
    #include<stdio.h>#include<iostream>usingnamespacestd;typedefcharTElemType;typedefvoidStatus;typedefintElemType;typedefstructBiTNode{ TElemTypedata; BiTNode*lchild,*rchild;}BiTNode,*BiTree;voidCreateBiTree(BiTree
  • 2023-11-16树算法题
    目录1、计算二叉树中所有结点个数2、计算二叉树中所有叶子节点的个数3、计算二叉树中所有双分支的节点个数4、计算二叉树的深度5、找出二叉树中最大值的点6、判断两个二叉树是否相似(指都为空或者都只有一一个根节点,或者左右子树都相似)7、把二叉树所有节点左右子树交换8
  • 2023-11-03后序遍历非递归(作业
    #define_CRT_SECURE_NO_WARNINGS#defineMax64#include<stdio.h>#include<stdlib.h>//二叉树的定义typedefstructnode{ chardata; intvisit; structnode*lchild; structnode*rchild;}bitree;//栈的定义typedefstruct{ bitree*data[Max]; in
  • 2023-10-232023年10月23日
    数据结构代码练习,关于2020年8511.二叉树的层次遍历//数据结构typedefstructBiTree{Datatypedata;structBiTree*left,*right;/*添加代码完成哈夫曼编码intlayer,weight;*/}TreeNode,*Bitree;voidleverodertraversal(BiTreeT){ if(T==NULL) return; /*
  • 2023-10-18星期三
    二叉树的链式结构二叉树的数据结构:typedefstructNode{chardata;structNode*lchild,*rchild;}*Bitree,BiNode;分别为根,左孩子,右孩子二叉树的创建,先序遍历的方式如输入 “AB#CD###E#F##”voidcreatBitree(Bitree&T){charch;cin>>ch;if(ch=='#')
  • 2023-08-27二叉树用顺序表实现 C++代码实现
    /*二叉树用顺序表实现*/#include<iostream>usingnamespacestd;/*完全二叉树顺序表的定义*/#defineMAX_BITREE_SIZE100typedefintSqBiTree[MAX_BITREE_SIZE];/*创建一个二叉树顺序表*/voidCreateBiTree(SqBiTree&T){inti;cout<<"输入元素个数:";
  • 2023-08-02二叉树的顺序实现
    二叉树的顺序实现////main.c//SqBiTree////CreatedbyEasonon2020/8/7.//Copyright©2020Eason.Allrightsreserved.//#include<stdio.h>#defineOK1#defineERROR0#defineTRUE1#defineFALSE0#defineMAXSIZE100typedefintStatus;//作
  • 2023-07-03tree-test
    #include<iostream>#include<stack>usingnamespacestd;typedefstructBiTNode{ chardata; structBiTNode*lchild; structBiTNode*rchild;}BiTNode,*BiTree;voidCreateTree(BiTree*Tree){ charch; ch=getchar(); if(ch=='.')
  • 2023-06-24二叉树
    #include<stdio.h>#include<stdlib.h>#include<malloc.h>typedefstructBTNode{ chardata; structBTNode*lchild; structBTNode*rchild;}*BiTree;voidcreateBiTree(BiTree*t){//此处补充代码,输入二叉树的先序遍历序列建立二叉树 chars;
  • 2023-06-21交换二叉树
    #include<stdio.h>#include<stdlib.h>#include<malloc.h>typedefstructBTNode{ chardata; structBTNode*lchild; structBTNode*rchild;}*BiTree;voidcreateBiTree(BiTree*t){//此处补充代码,输入二叉树的先序遍历序列建立二叉树 chars;
  • 2023-05-06计算二叉树深度
    解决思路如果是空树,则深度为0;否则,递归计算左子树的深度记为m,递归计算右子树的深度记为n,二叉树的深度则为m与n的较大者加1。intDepth(BiTreeT){if(T==NULL)return0;else{m=Depth(T->lchild);n=Depth(T->rchild);if(m>n)return(m+1);
  • 2023-05-06二叉树的操作
    二叉树的操作二叉树的复制如果是空树,递归结束否则,申请新结点的空间,复制根结点递归复制左子树递归复制右子树代码实现#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<vector>#include<cstring>#include<unordered_se
  • 2023-04-24二叉树的遍历(递归算法)
    //二叉树的遍历(递归算法)#include<stdio.h>#include<malloc.h>typedefstructBiTNode{intdata;structBiTNode*lchild,*rchild;//存储二叉树的左孩子和右孩子}BiTNode,*BiTree;voidInitTree(BiTree&root){root=(BiTNode*)malloc(sizeof(BiTNo
  • 2023-04-17biTree
    #include<stdio.h>#include<stdlib.h>typedefcharTElemType;typedefstructBiTNode{TElemTypedata;structBiTNode*lchild,*rchild;}BiTNode,*BiTree;typedefBiTreeSElemType;#defineSTACK_INIT_SIZE100#defineSTACKINCR
  • 2023-04-15二叉树的创建和中序及后序遍历
    二叉树的创建和中序及后序遍历二叉的先序创建使用#号来表示该结点为null实现代码先进行先序创建然后进行先序遍历#include<iostream>#include<algorithm>#include<cstdio>#include<cstring>#include<vector>#include<cstring>#include<unordered_set>#includ
  • 2023-04-1115.6二叉排序树删除实战
    #include<stdio.h>#include<stdlib.h>typedefintKeyType;typedefstructBSTNode{KeyTypekey;structBSTNode*lchild,*rchild;}BSTNode,*BiTree;//非递归的创建二叉查找数intBST_Insert(BiTree&T,KeyTypek){BiTreeTreeNew=(BiTree)cal
  • 2023-04-1115.5二叉排序树原理及建树实战
    #include<stdio.h>#include<stdlib.h>typedefintKeyType;typedefstructBSTNode{KeyTypekey;structBSTNode*lchild,*rchild;}BSTNode,*BiTree;//非递归的创建二叉查找数intBST_Insert(BiTree&T,KeyTypek){BiTreeTreeNew=(BiTree)cal
  • 2023-04-0914.7.2014年41题真题讲解
    function.h////Createdby93757on2023/3/21.//#ifndefINC_1_TREE_FUNCTION_H#defineINC_1_TREE_FUNCTION_H#include<stdio.h>#include<stdlib.h>typedefintBiElemType;typedefstructBiTNode{BiElemTypeweight;//c就是书籍上的data
  • 2023-04-0914.6二叉树的层序遍历实战
    function.h////Createdby93757on2023/3/21.//#ifndefINC_1_TREE_FUNCTION_H#defineINC_1_TREE_FUNCTION_H#include<stdio.h>#include<stdlib.h>typedefcharBiElemType;typedefstructBiTNode{BiElemTypec;//c就是书籍上的datastru
  • 2023-04-09二叉树前序中序后序遍历实战
    function函数////Createdby93757on2023/3/21.//#ifndefINC_1_TREE_FUNCTION_H#defineINC_1_TREE_FUNCTION_H#include<stdio.h>#include<stdlib.h>typedefcharBiElemType;typedefstructBiTNode{BiElemTypec;//c就是书籍上的datastru
  • 2023-04-03二叉树一点操作
    #include<stdio.h>#include<stdlib.h>typedefstructTree{intdata;structTree*lchild,*rchild;}Tree,*BiTree;BiTreeCreateLink(){intdata;inttemp;BiTreeT;scanf("%d",&data);temp=getchar()