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

ps做汽车网站下载网络推广专员招聘

ps做汽车网站下载,网络推广专员招聘,soho没有注册公司 能建一个外贸网站吗,襄阳微网站建设AVL树的插入 在向一棵本来高度平衡的AVL树中插入一个新节点时#xff0c;如果树中某个结点的平衡因子的绝对值 1#xff0c;则出现了不平衡。设新插入结点为P#xff0c;从结点P到根节点的路径上#xff0c;每个结点为根的子树的高度都可能增加1#xff0c;因此在每…AVL树的插入 在向一棵本来高度平衡的AVL树中插入一个新节点时如果树中某个结点的平衡因子的绝对值 1则出现了不平衡。设新插入结点为P从结点P到根节点的路径上每个结点为根的子树的高度都可能增加1因此在每执行一次二叉搜索树的插入运算后都需从新插入的结点P开始沿该结点插入的路径向根节点方向回溯修改各结点的平衡因子调整整棵树的高度恢复被破坏的平衡性质。 AVL树插入算法 新节点P的平衡因子为0但其双亲结点Pr的平衡因子有三种情况 1、结点Pr的平衡因子为0 在Pr的较矮的子树上插入新节点结点Pr平衡其高度没有增加此时从Pr到根路径上各结点为根的子树的高度不变即各结点的平衡因子不变结束平衡化处理。 2、结点Pr的平衡因子的绝对值为1 插入前Pr的平衡因子为0插入后以Pr为根的子树没有失去平衡但该子树的高度增 加需从该结点Pr向根节点方向回溯继续查看Pr的双亲结点的平衡性。 3、结点Pr的平衡因子的绝对值为2 新节点在较高的子树插入需要做平衡化处理 若Pr 2说明右子树高设Pr的右子树为q 当q的平衡因子为1执行左单旋转 当q的平衡因子为-1执行先右后左双旋转 若Pr -2说明左子树高设Pr的左子树为q 当q的平衡因子为-1执行右单旋转 当q的平衡因子为1执行先左后右双旋转 具体代码 #includeiostream   using namespace std; templateclass K, class V struct AVLTreeNode { AVLTreeNodeK, V* _pleft; AVLTreeNodeK, V* _pright; AVLTreeNodeK, V* _pParent; K _key; V _value; int _bf; AVLTreeNode(const K key, const V value) :_pleft(NULL) , _pright(NULL) ,_pParent(NULL) , _key(key) ,_value(value) ,_bf(0) {} }; templateclass K, class V class AVLTree { typedef AVLTreeNodeK, V Node; public: AVLTree() :_pRoot(NULL) {} AVLTree(const AVLTreeK, V t); AVLTreeK, V operator(const AVLTreeK, V t); ~AVLTree() { _Destory(_pRoot); } public: bool Insert(const K key, const V value) { if(NULL _pRoot) { _pRoot new Node(key, value); return true; } //寻找插入位置 Node* parent NULL; Node* pCur _pRoot; while(pCur) { if(key pCur-_key) { parent pCur; pCur pCur-_pleft; } else if(key pCur-_key) { parent pCur; pCur pCur-_pright; } else return false; } pCur new Node(key, value); //插入 if(key parent-_key) { parent-_pleft pCur; } else { parent-_pright pCur; } pCur-_pParent parent; //更新平衡因子 while(parent) { if(parent-_pleft pCur) { parent-_bf--; } else { parent-_bf; } if(parent-_bf 0) { break; } else if(1 parent-_bf || parent-_bf -1) { pCur parent; parent pCur-_pParent; } else { if(parent-_bf 2) { if(pCur-_bf 1) _RotateL(parent); else if(pCur-_bf -1) _RotateRL(parent); } else if(parent-_bf -2) { if(pCur-_bf -1) _RotateR(parent); else if(pCur-_bf 1) _RotateLR(parent); } break; } } return true; } void Inorder()     //中序遍历 { _Inorder(_pRoot); cout endl; } bool IsBalance()    //判断是否平衡 { int height 0; return _IsBalance(_pRoot, height); } private: void _RotateR(Node* parent) { Node* subL parent-_pleft; Node* subLR subL-_pright; parent-_pleft subLR; if(subLR) subLR-_pParent parent; subL-_pright parent; Node* pParent parent-_pParent; parent-_pParent subL; if(pParent NULL) { _pRoot subL; subL-_pParent NULL; } else { if(pParent-_pleft parent) { pParent-_pleft subL; } else { pParent-_pright subL; } subL-_pParent pParent; } subL-_bf parent-_bf 0; } void _RotateL(Node* parent) { Node* subR parent-_pright; Node* subRL subR-_pleft; parent-_pright subRL; if(subRL) subRL-_pParent parent; subR-_pleft parent; Node* pParent parent-_pParent; parent-_pParent subR; if(pParent NULL) { _pRoot subR; subR-_pParent NULL; } else { if(pParent-_pleft parent) { pParent-_pleft subR; } else { pParent-_pright subR; } subR-_pParent pParent; } subR-_bf parent-_bf 0; } void _RotateRL(Node* parent) {         Node* subR parent-_pright;           Node* subRL subR-_pleft;           _RotateR(subR);               _RotateL(parent);                   int bf subRL-_bf;              if (bf 0)           {                 subRL-_bf parent-_bf subR-_bf 0;          }              else if (bf -1)           {               subRL-_bf 0;               parent-_bf 1;               subR-_bf 0;           }              else if (bf 1)           {               subRL-_bf 0;               parent-_bf 0;               subR-_bf 1;           }  } void _RotateLR(Node* parent) {         Node* subL parent-_pleft;           Node* subLR subL-_pright;           _RotateL(subL);           _RotateR(parent);           int bf subLR-_bf;              if (bf 0)           {               subLR-_bf parent-_bf subL-_bf 0;           }              else if (bf 1)           {               subLR-_bf 0;               parent-_bf 1;               subL-_bf 0;           }              else if (bf -1)           {               subLR-_bf 0;               parent-_bf 0;               subL-_bf -1;           }   } void _Destory(Node* pRoot) { if (_pRoot NULL) return; _Destory(pRoot-_pleft); _Destory(pRoot-_pright); delete pRoot; pRoot NULL; } protected: void _Inorder(Node* pRoot)     //中序 { if (pRoot NULL) { return; } _Inorder(pRoot-_pleft); cout pRoot-_key ; _Inorder(pRoot-_pright); } bool _IsBalance(Node* pRoot, int height) { if (pRoot NULL) { height 0; return true; } int left, right; if (_IsBalance(pRoot-_pleft, left) _IsBalance (pRoot-_pright, right) abs(right - left) 2) { height left right ? left 1 : right 1; if (pRoot-_bf ! right - left) { cout 平衡因子异常 pRoot-_key  endl; return false; } return true; } else { return false; } } size_t _Height(Node* pRoot)    //高度 { if (pRoot NULL) { return 0; } int l _Height(pRoot-_pleft); int r _Height(pRoot-_pright); return l r ? l 1 : r 1; } private: Node* _pRoot; }; int main() { AVLTreeint, int t; t.Insert(3,3); t.Insert(7,7); t.Insert(11,11); t.Insert(14,14); t.Insert(15,15); t.Insert(18,18); t.Insert(16,16); t.Insert(26,26); t.Insert(9,9); t.Inorder();       cout IsBalance? t.IsBalance() endl;   system(pause); return 0; }
http://www.zqtcl.cn/news/408137/

相关文章:

  • 荥阳网站开发WordPress 采集文章 图片
  • 网站域名登记证明文件音乐网站开发需要什么语言工具
  • 贵州域网网站建设东莞做外贸网站的公司
  • ps怎么做华为网站界面怎样做网站步骤
  • 免费做试卷的网站或试卷seo 培训教程
  • 创意网站建设价格多少最新新闻热点事件2022年8月
  • wordpress用户登录界面插件重庆网站排名优化公司
  • 网站整体建设方案设计wordpress 插件升级慢
  • 淄博网站制作升级优化青岛品牌网站建设价格
  • 网站后台管理系统模块星星wordpress模板
  • 网站统计 中文域名优化英语
  • 自己做视频的网站吗怎么建设维护学校的网站
  • 广州网站建设好公司鲁权屯网站建设
  • 网站多数关键词网站使用mip后效果怎么样
  • 如何介绍自己做的网站建设三库一平台
  • 郑州网站商城建设iframe 一直网站底部
  • 1688网站怎么样百度一下你知道
  • 做电商图的设计网站蚌埠网页设计培训
  • 江苏省建设工程质量监督站网站手机网站 案例
  • 优而思 网站科技自立自强是国家强盛之基
  • 去哪里购买网站空间专门做家居的网站
  • 网站信息安全建设方案公众号网站建设
  • 网站的设计方案淘宝大数据查询平台
  • 深圳营销型网站建设 龙华信科网站项目有需要什么技术支持
  • 开源网站模板cms网店推广实训总结
  • 常见的电子商务网站有哪些建设校园门户网站信息意义
  • 象山经济开发区建设有限公司网站足球比赛直播app
  • 国外做mg动画的网站大全网站打不开 别的电脑能打开
  • 手机怎么创网站西宁企业做网站
  • 网站主机多大wordpress连接错误