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

做网站网上接单石家庄发布最新消息

做网站网上接单,石家庄发布最新消息,建设一个网站的技术可行性研究,网络系统管理比赛以下内容源于慕课网的学习整理#xff0c;如有侵权#xff0c;请告知删除。 树存在概念中#xff0c;是对数组或者链表的一种操作方式的概念。 一、与树有关的一些基础概念 #xff08;1#xff09;树 有限节点的集合#xff1b; #xff08;2#xff09;度 某个节点的…以下内容源于慕课网的学习整理如有侵权请告知删除。 树存在概念中是对数组或者链表的一种操作方式的概念。 一、与树有关的一些基础概念 1树 有限节点的集合 2度 某个节点的直接孩子数目 3叶节点 终端节点 4祖先 所有在它之上的节点 5深度 节点的深度节点所处的位置树的深度整棵树的深度 6二叉树 所有节点的度都小于等于2 7二叉树的遍历 前中后是针对“根”来说的。 8作用实例 人机对战 二、二叉树的数组实现 1、换算公式 父节点下标*21得到父节点的左孩子节点的下标父节点下标*22得到父节点的右孩子节点的下标 2、示意图 括号里面表示的是索引或者说节点序号外面的是数据。慕课网中只是按照这个图来进行查找遍历查找、插入已经确定在哪个位置上出入了、删除删除后赋值为0等操作。 三、二叉树的链表实现 1、节点要素 数据左孩子指针右孩子指针父指针索引这里用来表征节点的序号 2、删除元素 要求把对应的子节点也删除掉也可能要求只删除该点然后该点的孩子节点指向该点的父节点 3、前序遍历根左右 4、中序遍历左根右 首先是左526然后是根0接着是右897 然后对526进行同样的操作即左是2根是5右是6则排序结果是256 同理对897进行同样的操作即左是9根是8右是7则排序结果是987 最后合成为256 0 987。 5、后序遍历左右根 首先是左526然后是右897接着是根0 然后对526进行同样的操作即左是2右是6根是5则排序结果是265 同理对897进行同样的操作即左是9右是7根是8则排序结果是978 最后合成为265  978 0。 6、编码实现 树类、节点类节点类包含五要素数据左孩子指针右孩子指针父指针索引这里用来表征节点的序号前序遍历中序遍历、后序遍历就调换相应的位置即可。对树的遍历操作落实在根节点调用遍历函数。 node.h #ifndef NODE_H #define NODE_H class Node{ public :Node();int index;int data;Node *pLNOde;Node *pRNode;Node *pParent;Node *SerchNode(int index);void deleteNode();void Preorder();void Midorder();void Postorder(); }; #endifnode.cpp#include Node.h #include iostream using namespace std;Node::Node() {index0;data0;pLNOdeNULL;pRNodeNULL;pParentNULL; };Node* Node::SerchNode(int index) {Node *tempNULL;if (this-indexindex)return this;if (this-pLNOde!NULL){ tempthis-pLNOde-SerchNode(index);if (temp!NULL){return temp;}}if (this-pRNode!NULL){tempthis-pRNode-SerchNode(index);if (temp!NULL){return temp;}}return NULL; };void Node::deleteNode() {if(this-pLNOde!NULL) {this-pLNOde-deleteNode();}if (this-pRNode!NULL){this-pRNode-deleteNode();}if (this-pParent!NULL){if (this-pParent-pLNOdethis){this-pParent-pLNOdeNULL;}if (this-pParent-pRNodethis){this-pParent-pRNodeNULL;}}delete this; };void Node::Preorder() {coutthis-data this-indexendl;if (this-pLNOde!NULL){this-pLNOde-Preorder();}if (this-pRNode!NULL){this-pRNode-Preorder();} };void Node::Midorder() {if (this-pLNOde!NULL){this-pLNOde-Midorder();}coutthis-data this-indexendl;if (this-pRNode!NULL){this-pRNode-Midorder();} };void Node::Postorder() {if (this-pLNOde!NULL){this-pLNOde-Postorder();}if (this-pRNode!NULL){this-pRNode-Postorder();}coutthis-data this-indexendl; };tree.h #ifndef Tree_H #define Tree_H #include Node.hclass Tree { public:Tree();~Tree();Node *SerchNode(int index);//查找索引为index的那个节点并返回指向该节点的指针bool addNode(int index,int direction,Node *node);//添加在索引为index的节点上添加一个节点node//左右方向由direction决定bool deleteNode(int index,Node *node);//删除void Preorder();//前序void Midorder();//中序void Postorder();//后序 private:Node *p_node;};#endiftree.cpp#include Tree.h #include Node.h #include iostream using namespace std;Tree::Tree() {p_nodenew Node(); };Tree::~Tree() {deleteNode(0,NULL);//这里调用的是tree中的删除节点函数从根节点0开始 };Node *Tree::SerchNode(int index) {return p_node-SerchNode(index);};bool Tree::deleteNode(int index,Node *node) {Node *tempSerchNode(index);if (temp!NULL){if (node!NULL)//传入的Node可以为null。是null时表明不需要把要删除的节点的数据保存。{node-indextemp-index;node-datatemp-data;}temp-deleteNode();return true;}elsereturn false; };bool Tree::addNode(int index,int direction,Node *node) {Node *tempSerchNode(index);if (temp){Node *NewNodenew Node();if (NewNodeNULL){return false;}NewNode-datanode-data;NewNode-indexnode-index;if (direction0){temp-pLNOdeNewNode;NewNode-pParenttemp;}if (direction1){NewNode-pParenttemp;temp-pRNodeNewNode;}return true;}return false; };void Tree::Preorder() {p_node-Preorder(); }void Tree::Midorder() {p_node-Midorder(); }void Tree::Postorder() {p_node-Postorder(); }test.cpp#include Node.h #include Tree.h #include iostreamusing namespace std; /*0(0)1(1) 2(2)5(3) 7(4) 6(5) 9(6)*/ int main() {Tree *pnew Tree;//这里的p是指向根节点的指针Node *n2new Node;n2-data1;n2-index1;Node *n3new Node;n3-data2;n3-index2;Node *n4new Node;n4-data3;n4-index3;Node *n5new Node;n5-data4;n5-index4;Node *n6new Node;n6-data5;n6-index5;Node *n7new Node;n7-data6;n7-index6;Node *n8new Node;n8-data8;n8-index8;Node *n9new Node;n9-data9;n9-index9; Node *n10new Node;n10-data10;n10-index10;Node *n11new Node;n11-data11;n11-index11;p-addNode(0,0,n2);p-addNode(0,1,n3);p-addNode(1,0,n4);p-addNode(1,1,n5);p-addNode(2,0,n6);p-addNode(2,1,n7); // p-addNode(4,0,n8); // p-addNode(4,1,n9); // p-addNode(6,0,n10); // p-addNode(6,1,n11);Node *n18new Node;n18p-SerchNode(10);if (n18!NULL){coutindex:n18-indexendl;}//Node *n12new Node;//p-deleteNode(6,n12);p-Preorder();coutendl;p-Postorder();coutendl;p-Midorder();delete p;pNULL;system(pause);return 0; }
http://www.zqtcl.cn/news/295940/

相关文章:

  • 网站资源做缓存国外做饮料视频网站
  • 用asp.net做的购物网站西安手机网站制作
  • wordpress 自定义主题wordpress自带数据库优化
  • 电子商务网站建设与维护的考试用自己的电脑做网站划算
  • 微商招商网站源码wordpress怎么改后台
  • 哪些网站有搜索引擎作弊的社群营销平台有哪些
  • 建地方的网站前景苏州做视频网站广告公司
  • 制作网站的主题海口网站自助建站
  • dede二手车网站源码网络工程师
  • 吴桥网站新网站优化怎么做
  • 做网站要求什么条件0资本建设网站
  • 免费做网站排名洛阳软件开发公司有哪些
  • 网站搜索优化方法东莞seo全网营销
  • 广州微网站建设哪家好wordpress怎样将小工具放到左侧
  • 汕头网站搜索优化嘉兴网络项目建站公司
  • 怎么查询网站是什么时候做的网站app的意义
  • 曹妃甸网站建设合肥的房产网站建设
  • 怎么做网站前台二级区域网站名
  • 服务器租用相关网站一个空间怎么放两个网站吗
  • 每个城市建设规划在哪个网站南宁seo怎么做优化团队
  • 做资讯类网站ccd设计公司官网
  • 写作网站5妙不写就删除抚州建设网站
  • 沙田网站建设公司网站风格设计原则
  • 安徽省建设监理网站黑群晖可以做网站吗
  • 手机百度seo快速排名搜索引擎优化目标
  • 长春 房地产网站建设网站建设 合同
  • 电商专业培训网站建设wordpress内置播放器
  • 创意网站设计模板点击器免费版
  • 做的不错的h5高端网站网站是怎么优化的
  • 淄博做网站优化佛山 做网站公司