当前位置: 首页 > news >正文

网站建设流程总结/服装品牌策划方案

网站建设流程总结,服装品牌策划方案,做网站的cnfg,100个无水印短视频素材基本术语: 节点的度:书中某一节点拥有的子节点数量。 数的度:该树中所有节点的度的最大值。 叶节点(终端节点):度为零的节点。 分支节点(非终端节点):度不为零的节点。 根节点(开始节…

 


 

基本术语:

节点的度:书中某一节点拥有的子节点数量。

数的度:该树中所有节点的度的最大值。

叶节点(终端节点):度为零的节点。

分支节点(非终端节点):度不为零的节点。

根节点(开始节点):树中的第一个节点。

内部节点:树中除了根节点之外的节点。

节点的层数:若根节点层数为1,根节点的第n代子节点的层数为n。

树的高度:书中的节点的最大层数。

有序树和无序树:若树中某一节点的子节点无序,则该树为无序树,否则为有序树。

森林:去掉一棵树的根节点后得到的n棵树。

树的特点:

1.树是一种很基础很重要的非线性结构。

2.除表头(树根)和表尾(叶节点)外,任何一个节点只有一个直接前驱,但有多个直接后继。

3.树是数据的有限集,树分为空树和非空树。 

  非空树:有且只有一个根节点。若根节点的子节点大于1,可以理解为这棵非空树有m棵相互独立的非空树组成。

4.树的递归特性(★★★):一颗非空树有若干子树组成,每一棵子树又由更小的子组成。


 

C++实现:

[MyTree.h]:无序树类模板头文件

#pragma oncetemplate<class T>
class MyTree
{
private:struct TreeNode  //定义私有,不让用户使用
    {T data;  //数据域,可以多个数据//指针域TreeNode *parent;   //节点的父指针TreeNode *child;    //子指针TreeNode *brother;    //兄弟指针  兄弟之间逐级管理
    };TreeNode *pRoot;   //根节点public:MyTree();~MyTree();void clear();void insertNode(const T& parentData, const T& insertData, bool insertChild = true); //默认插入为子节点//bool isFind(const T& findData);void preOrderPrint(TreeNode *root /*= pRoot*/);  //前序(前根)遍历void posOrderPrint(TreeNode *root /*= pRoot*/);  //前序(后根)遍历void inOrderPrint(TreeNode *root  /*= pRoot*/);   //中序(中根)遍历    TreeNode* getTreeRoot();
private:void _clear(TreeNode *root);        //用于clear()函数的实现,不提供接口TreeNode* _find(TreeNode *root, const T& findData);
};template<class T>
typename MyTree<T>::TreeNode* MyTree<T>::getTreeRoot()
{return pRoot;
}template<class T>
void MyTree<T>::inOrderPrint(TreeNode *root /*= pRoot*/)
{if (!root)return;inOrderPrint(root->child);std::cout << root->data << " ";inOrderPrint(root->brother);
}template<class T>
void MyTree<T>::posOrderPrint(TreeNode *root /*= pRoot*/)
{if (!root)return;posOrderPrint(root->child);posOrderPrint(root->brother);std::cout << root->data << " ";
}template<class T>
void MyTree<T>::preOrderPrint(TreeNode *root /*= pRoot*/)
{if (!root)return;std::cout << root->data << " ";preOrderPrint(root->child);preOrderPrint(root->brother);
}template<class T>
void MyTree<T>::insertNode(const T& parentData, const T& insertData, bool insertChild /*= true*/)
{TreeNode *tempInsertNode = new TreeNode;    //生成一个待插入的节点tempInsertNode->data = insertData;tempInsertNode->parent = NULL;tempInsertNode->child = NULL;tempInsertNode->brother = NULL;if (pRoot)  //判断树是否为空
    {TreeNode *findNode = _find(pRoot, parentData);    //找到插入位置if (findNode){//找到了插入位置if (insertChild){//在子节点插入TreeNode *temp = findNode->child;if (temp){while (temp->brother)temp = temp->brother;temp->brother = tempInsertNode;tempInsertNode->parent = findNode;}else{findNode->child = tempInsertNode;tempInsertNode->parent = findNode;}}else{//在兄弟节点插入if (findNode->brother){TreeNode *tempNode = findNode->brother;while (tempNode->brother)tempNode = tempNode->brother;tempNode->brother = tempInsertNode;tempInsertNode->parent = tempNode->parent;}else{//没有兄弟节点findNode->brother = tempInsertNode;tempInsertNode->parent = findNode->parent;}}}else{//如果没有找到插入位置  设计为插入在末尾std::cout << "can not find the parent,insert the data in the end" << std::endl;TreeNode *temp = pRoot;while (temp->child)temp = temp->child;temp->child = tempInsertNode;tempInsertNode->parent = temp;}}else{//树为空的情况//         TreeNode *temp = new TreeNode;//         temp->data = insertData;//         temp->parent = NULL;//         inNode->child = inNode->brother = NULL;pRoot = tempInsertNode;}
}template<class T>
typename MyTree<T>::TreeNode * MyTree<T>::_find(TreeNode *root, const T& findData)
{if (root)    /*递归结束条件  传入的的指针为空  例如判断叶节点是  将叶子节点的子节点传入递归函数,不满足条件直接返回空*/{//先判断本节点 在判断子节点  最后判断兄弟节点 找到直接返回 不继续找if (root->data == findData)        //判断当前节点是否为 需要找的节点return root;TreeNode * temp = _find(root->child, findData);if (temp)return temp;if (temp = _find(root->brother, findData))return temp;}return NULL;    //若没有找到  返回为空
}template<class T>
void MyTree<T>::_clear(TreeNode *root)
{//用递归删除所有节点   树的递归特性if (root){_clear(root->child);_clear(root->brother);  //先删除兄弟和先删除儿子一样delete[]root;        //必须先删除兄弟和儿子后才能删除自己root = nullptr;        //所有内存被释放后 指针置空
    }
}template<class T>
void MyTree<T>::clear()
{_clear(pRoot);  //不需要再进行判空 ,_clear()中会判断
}template<class T>
MyTree<T>::~MyTree()
{clear();
}template<class T>
MyTree<T>::MyTree()
{pRoot = nullptr;
}

代码测试:

 

// 无序树.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "MyTree.h"
#include<iostream>
using namespace std;int _tmain(int argc, _TCHAR* argv[])
{MyTree<int> tree;std::cout << "tree:" << endl;;tree.insertNode(1, 1);cout << 1 << '\n' << '|' << endl;;tree.insertNode(1, 2, 1);tree.insertNode(2, 5, 0);tree.insertNode(2, 9, 0);cout << 2 << "" << 5<<"— —"<<9<<endl;cout << '|' << "  " << "|" <<"     "<<"|"<< endl;tree.insertNode(2, 3, 1);tree.insertNode(5, 6, 1);tree.insertNode(6, 7, 0);tree.insertNode(9, 10, 1);cout << 3 << "  " << 6 << "" << 7 <<" "<< 10 << endl;cout << "|" << "     " << "|" << endl;tree.insertNode(3, 4, 1);tree.insertNode(7, 8, 1);cout << 4 << "     " << 8 << "\n\n"<<endl;std::cout << "前序遍历:";tree.preOrderPrint(tree.getTreeRoot());std::cout << std::endl;std::cout << "后序遍历:";tree.posOrderPrint(tree.getTreeRoot());std::cout << std::endl;std::cout << "中序遍历:";tree.inOrderPrint(tree.getTreeRoot());std::cout << std::endl;std::cin.get();return 0;
}

 

测试结果:

 

 

 

 

转载于:https://www.cnblogs.com/daniumeng/p/8597862.html

http://www.lbrq.cn/news/1116379.html

相关文章:

  • 找生意做去哪个网站/佛山seo教程
  • 个人中心页面/推广排名seo
  • 如何设置网站图标favicon.ico/镇江网站制作公司
  • 商业地产网站建设/石家庄网站优化
  • 日本产品和韩国产品哪个好/沈阳seo代理计费
  • 自建的电子网站如何做推广/百度百科优化
  • 秦皇岛做网站/广告投放怎么做
  • zz手表网站/seo排名优化收费
  • 青岛企业如何建网站/seo搜索是什么
  • 专做户外装备测评视频网站/seo sem是什么意思
  • 网站建设技术经费预算/全网网络营销
  • 做自动发货网站/长沙网络推广只选智投未来
  • 集团公司网站建设策划/google下载安卓版
  • 河南建设银行处理违章网站/搜索引擎推广与优化
  • 成品网站w灬源码1688网页版/阿里云建站费用
  • 广东广州电脑个人建站/看网站搜什么关键词
  • 清远专业网站建设/怎么在百度做宣传广告
  • 国内最大网站制作公司/百度seo 站长工具
  • 空间注册网站/百度关键词排名查询接口
  • 北京 个人网站 备案/品牌运营管理公司
  • 留住用户网站/什么是软文营销?
  • 天涯武汉论坛/网站seo教材
  • 邯郸小学网站建设/抖音搜索优化
  • 重庆网站设计定制/国外域名注册
  • 自己的网站是什么样子的/营销网站的宣传、推广与运作
  • 电子商务网站建设阶段/十大骗子教育培训机构
  • 青岛家乐福网上商城/seo在线教学
  • 做网站需要多少/网站seo百度百科
  • html5做图书馆网站/软件开发外包公司
  • 免费推广seo策略方法/seo外包如何
  • 全面升级!WizTelemetry 可观测平台 2.0 深度解析:打造云原生时代的智能可观测平台
  • 【中等】题解力扣22:括号生成
  • 如何解决WordPress数据库表损坏导致的错误
  • 主机安全---开源wazuh使用
  • 从0开始学习R语言--Day48--Calibration Curves 评估模型
  • webpack和vite对比