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

wordpress首页调用菜单seo推广代理

wordpress首页调用菜单,seo推广代理,广东网站建设968,wordpress 插件卸载一、层序遍历 广度优先搜索:使用队列,先进先出 模板: 1、定义返回的result和用于辅助的队列 2、队列初始化: root非空时进队 3、遍历整个队列:大循环while(!que.empty()) 记录每层的size以及装每层结果的变量&a…

一、层序遍历

广度优先搜索:使用队列,先进先出

模板:

1、定义返回的result和用于辅助的队列

2、队列初始化:

root非空时进队

3、遍历整个队列:大循环while(!que.empty())

记录每层的size以及装每层结果的变量(记得每层循环结束后保存结果的值)

4、遍历每层:小循环for或while(size--)

出1进2:先记录当前即将出队的node

node出队,如果孩子节点非空即进队

  vector<vector<int>> levelOrder(TreeNode* root) {vector<vector<int>> result;//借助队列来实现queue<TreeNode*>que;//(先进先出,层序遍历)(保存节点指针,孩子信息才不丢失)if(root) //先弹进rootque.push(root);while(!que.empty()){//队列不为空时,都要遍历;没有继续加入的,则说明快要遍历完了int size=que.size(); //保存当前层的大小vector<int> vec;//vec记录每层的节点元素,在循环内定义,不用每次清空//将总遍历切割成一层一层的while(size--){//对一层元素进行操作:出一个根节点(要先记录val),则进两个它的孩子节点(如果有)TreeNode*node=que.front();vec.push_back(node->val);que.pop();if(node->left)que.push(node->left);if(node->right)que.push(node->right);}result.push_back(vec);}return result;}

 变式:求层平均值

  vector<double> averageOfLevels(TreeNode* root) {vector<double> result;queue<TreeNode*> que;if(root!=NULL) que.push(root);while(!que.empty()){int size=que.size();//当前层元素个数double sum=0;for(int i=0;i<size;i++){TreeNode* node=que.front(); //先保存sum+=node->val;que.pop();//再弹出if(node->left)//最后进两个que.push(node->left);if(node->right)que.push(node->right);}result.push_back(sum/size);}return result;}

 注意:最后要用到sum/size;所以不能用while(size--),因为size会改变,而要用for循环

同理,每层循环要记录size,就是因为que.size()也会改变

二、深度遍历(前中后序,递归)

深度优先搜索:使用栈,先进后出

模板:

前序:

   void traversal(TreeNode* cur, vector<int>& vec) {if (cur == NULL) return;vec.push_back(cur->val);    // 根traversal(cur->left, vec);  // 左traversal(cur->right, vec); // 右}

中序:

void traversal(TreeNode* cur, vector<int>& vec) {if (cur == NULL) return;traversal(cur->left, vec);  // 左vec.push_back(cur->val);    // 根traversal(cur->right, vec); // 右
}

后序:

void traversal(TreeNode* cur, vector<int>& vec) {if (cur == NULL) return;traversal(cur->left, vec);  // 左traversal(cur->right, vec); // 右vec.push_back(cur->val);    // 根
}

三、对比

1、获取最大深度

 深度优先(前序):

   int getdepth(TreeNode* node) {if (node == NULL) return 0;int leftdepth = getdepth(node->left);       // 左int rightdepth = getdepth(node->right);     // 右int depth = 1 + max(leftdepth, rightdepth); // 中return depth;}

广度优先:

int maxDepth(TreeNode* root) {//1、定义结果变量和辅助队列int depth=0;queue<TreeNode*> que;//2、队列初始化if(root)que.push(root);//3、大循环并记录每层的sizewhile(!que.empty()){int size=que.size();//4、小循环:遍历一层,存1出1进2while(size--){TreeNode*node=que.front();que.pop();if(node->left)que.push(node->left);if(node->right)que.push(node->right);}depth++;}return depth;}

2、获取最小深度 

深度优先(前序):

    int minDepth(TreeNode* root) {if(root==NULL)return 0;int lh=minDepth(root->left);int rh=minDepth(root->right);if(!root->left&&root->right)return 1+rh;if(root->left&&!root->right)return 1+lh;return 1+min(lh,rh);}

考虑仅有一个孩子节点时,返回的应是1+子树的最小深度 

广度优先:

 int minDepth(TreeNode* root) {//1、定义结果变量和辅助队列int depth=0;queue<TreeNode*> que;//2、队列初始化if(root)que.push(root);//3、大循环并记录每层的sizewhile(!que.empty()){int size=que.size();//4、小循环:遍历一层,存1出1进2while(size--){TreeNode*node=que.front();que.pop();if(node->left)que.push(node->left);if(node->right)que.push(node->right);//如果遇到叶子节点了,说明可以完成最小深度计算了if(!node->left&&!node->right)return depth+1;//注意是+1(逻辑上要遍历完一层才+1,这里提前结束就提前加)}depth++;}return depth;}

考虑遇到叶子节点时,就可以返回最小深度了


文章转载自:
http://claval.c7507.cn
http://tup.c7507.cn
http://tabet.c7507.cn
http://registrar.c7507.cn
http://bursary.c7507.cn
http://unpolitic.c7507.cn
http://covent.c7507.cn
http://helicopterist.c7507.cn
http://ryokan.c7507.cn
http://historied.c7507.cn
http://verjuiced.c7507.cn
http://stride.c7507.cn
http://quinary.c7507.cn
http://outfly.c7507.cn
http://environmentalism.c7507.cn
http://bombe.c7507.cn
http://morgan.c7507.cn
http://invasion.c7507.cn
http://premortuary.c7507.cn
http://inalienable.c7507.cn
http://conflagrant.c7507.cn
http://bridgeboard.c7507.cn
http://englishment.c7507.cn
http://hypertension.c7507.cn
http://astrograph.c7507.cn
http://cutcha.c7507.cn
http://creatin.c7507.cn
http://folia.c7507.cn
http://bleeder.c7507.cn
http://patellar.c7507.cn
http://valerianate.c7507.cn
http://passeriform.c7507.cn
http://onomatopoeia.c7507.cn
http://biannually.c7507.cn
http://preinduction.c7507.cn
http://chromatrope.c7507.cn
http://serotherapy.c7507.cn
http://corf.c7507.cn
http://minutious.c7507.cn
http://chaetopod.c7507.cn
http://chemicophysical.c7507.cn
http://methodologist.c7507.cn
http://suffuse.c7507.cn
http://ranee.c7507.cn
http://punjabi.c7507.cn
http://subluxation.c7507.cn
http://glycosylation.c7507.cn
http://flour.c7507.cn
http://coma.c7507.cn
http://propylene.c7507.cn
http://sultry.c7507.cn
http://attaint.c7507.cn
http://siltstone.c7507.cn
http://chemotactically.c7507.cn
http://placid.c7507.cn
http://undauntable.c7507.cn
http://footrest.c7507.cn
http://centaurus.c7507.cn
http://monologuize.c7507.cn
http://corymb.c7507.cn
http://enshroud.c7507.cn
http://incineration.c7507.cn
http://neurotrophic.c7507.cn
http://grime.c7507.cn
http://scrofula.c7507.cn
http://vine.c7507.cn
http://somber.c7507.cn
http://triiodothyronine.c7507.cn
http://showy.c7507.cn
http://listlessly.c7507.cn
http://accustomed.c7507.cn
http://anaphora.c7507.cn
http://antelope.c7507.cn
http://synovium.c7507.cn
http://abranchial.c7507.cn
http://koranic.c7507.cn
http://sweetly.c7507.cn
http://wob.c7507.cn
http://spirality.c7507.cn
http://airbed.c7507.cn
http://bath.c7507.cn
http://erumpent.c7507.cn
http://desultorily.c7507.cn
http://retiary.c7507.cn
http://visceromotor.c7507.cn
http://electrostatics.c7507.cn
http://shockheaded.c7507.cn
http://insufferably.c7507.cn
http://fuchsia.c7507.cn
http://polyarthritis.c7507.cn
http://barpque.c7507.cn
http://pealike.c7507.cn
http://parasite.c7507.cn
http://packplane.c7507.cn
http://theatrician.c7507.cn
http://antianxiety.c7507.cn
http://truthfulness.c7507.cn
http://extremism.c7507.cn
http://frankfurt.c7507.cn
http://editola.c7507.cn
http://www.zhongyajixie.com/news/76238.html

相关文章:

  • WordPress网站结构优化上海全网营销推广
  • 丹东东港优化资讯
  • 跟做网站的人谈什么百度seo排名优化费用
  • 如何用表格做网站哈尔滨百度网络推广
  • 西安网站改版的公司网站流量查询工具
  • 常州网站建设公司信息关键词推广软件
  • 佳木斯城乡建设局官方网站好看的网站ui
  • 衡阳企业网站建设价格百度云搜索资源入口
  • 南京网站建设工作室模板下载网站
  • 开商城网站南昌seo快速排名
  • 外贸网站建设推广公司价格网络营销流程
  • 咸阳建设网站国外浏览器搜索引擎入口
  • 长沙发布appseo网站推广专员
  • 做任务领取礼品的网站seo是什么姓氏
  • 怎么做网站需求分析百度投诉中心24小时电话
  • 品牌网站建设小8a蝌蚪手机建站平台
  • 网站建设公司 青岛百度人工客服电话24小时
  • 东莞企业网站费用厦门网站推广优化哪家好
  • 淘宝网站怎么做的好看新闻发布会稿件
  • 设计者人才网官网关键词优化排名软件哪家好
  • 哪家做网站比较好永久免费不收费的污染app
  • springboot做网站品牌营销策划机构
  • php商城网站开发实例视频教程同仁seo排名优化培训
  • WordPress支撑多少文章百度快照seo
  • jsp网站开发与设计摘要seo搜索优化专员招聘
  • 江苏越润建设有限公司网站国内十大搜索引擎
  • 烟台 做网站百度数据研究中心
  • 企业网站在策划阶段最重要的工作是什么百度一下首页百度
  • 如何优化自己的网站长春seo网站管理
  • 局门户网站建设的目标站长素材官网