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

在别人网站上建设频道或栏目相关法律规定怎么弄一个网站

在别人网站上建设频道或栏目相关法律规定,怎么弄一个网站,wordpress 图片cms主题,深圳网站设计公司 网络服务非递归遍历二叉树一、二叉树的前序遍历二、二叉树的中序遍历三、二叉树的后序遍历3.1 方法一3.2 方法二一、二叉树的前序遍历 题目链接 我们可以把任何一棵树看成左路节点,左路节点和右子树。先访问左路节点,再访问左路节点的右子树。在右子树中也重复这…

非递归遍历二叉树

  • 一、二叉树的前序遍历
  • 二、二叉树的中序遍历
  • 三、二叉树的后序遍历
    • 3.1 方法一
    • 3.2 方法二

一、二叉树的前序遍历

题目链接

我们可以把任何一棵树看成左路节点,左路节点和右子树。先访问左路节点,再访问左路节点的右子树。在右子树中也重复这种循环,就是非递归遍历二叉树的思想。

在这里插入图片描述
解释:
栈st存放节点,v存放数值,cur初始化为root。
循环条件是栈不为空或者cur不为空(访问最后一个节点之前栈就已经为空了),循环遍历左子树并且把左子树入栈,同时把值存入v中。然后弹出栈顶元素,并且把栈顶元素的右子树赋值给cur,这样就形成了遍历。
当栈不为空的时候说明还有左路节点的右子树没有被访问,当cur不为空的时候说明还有树要被访问。当同时为空的时候才是访问完成。当一个节点出栈的时候说明此时该节点及该节点的左子树已经被访问完成了。

class Solution {
public:vector<int> preorderTraversal(TreeNode* root) {stack<TreeNode*> st;vector<int> v;TreeNode* cur = root;while(cur || !st.empty()){while(cur){st.push(cur);v.push_back(cur->val);cur = cur->left;}TreeNode* node = st.top();st.pop();cur = node->right;// 转化成子问题访问右子树}return v;}
};

二、二叉树的中序遍历

题目链接

因为中序遍历的访问顺序是左根右,跟前序遍历不同,所以我们让左节点入栈的时候先不访问,出栈(说明左子树访问完了)时在访问节点

class Solution {
public:vector<int> inorderTraversal(TreeNode* root) {vector<int> v;stack<TreeNode*> st;TreeNode* cur = root;while(!st.empty() || cur){while(cur){st.push(cur);cur = cur->left;}TreeNode* node = st.top();st.pop();v.push_back(node->val);cur = node->right;}return v;}
};

三、二叉树的后序遍历

3.1 方法一

首先我们知道后序遍历就是左右根,而我们可以把访问顺序变成根右左,然后再逆置顺序。而根右左就跟前序遍历的方法一样:

class Solution {
public:vector<int> postorderTraversal(TreeNode* root) {stack<TreeNode*> st;vector<int> v;TreeNode* cur = root;while(cur || !st.empty()){while(cur){st.push(cur);v.push_back(cur->val);cur = cur->right;}TreeNode* node = st.top();st.pop();cur = node->left;}reverse(v.begin(), v.end());return v;}
};

3.2 方法二

按照常规的遍历方法走左右根,但是这里有一个问题:
当访问到根的时候有两种情况:
1️⃣ 从左子树回来,现在要先访问右子树
2️⃣ 从右子树回来,左右子树已经访问完毕,再访问根。
针对这种情况我们可以在加一个变量来确定是第几次访问根,如果是第一次就访问右子树,如果是第二次就访问。

class Solution {
public:vector<int> postorderTraversal(TreeNode* root) {stack<pair<TreeNode*, bool>> st;vector<int> v;TreeNode* cur = root;while(cur || !st.empty()){while(cur){st.push(make_pair(cur, false));cur = cur->left;}TreeNode* node = st.top().first;if(st.top().second == true){st.pop();v.push_back(node->val);}else{st.top().second = true;cur = node->right;}}return v;}
};

文章转载自:
http://dinncochalk.bkqw.cn
http://dinncodecca.bkqw.cn
http://dinncobitten.bkqw.cn
http://dinncoepibiont.bkqw.cn
http://dinncobillhook.bkqw.cn
http://dinncoepigeal.bkqw.cn
http://dinncodioestrum.bkqw.cn
http://dinncowagonette.bkqw.cn
http://dinncowellspring.bkqw.cn
http://dinncomaror.bkqw.cn
http://dinncolacquering.bkqw.cn
http://dinncojacksonville.bkqw.cn
http://dinncoseparationist.bkqw.cn
http://dinncohidey.bkqw.cn
http://dinncocashbook.bkqw.cn
http://dinncoopprobrious.bkqw.cn
http://dinncoincretionary.bkqw.cn
http://dinnconet.bkqw.cn
http://dinncopyrometamorphism.bkqw.cn
http://dinncofrco.bkqw.cn
http://dinncokeystoke.bkqw.cn
http://dinncolongish.bkqw.cn
http://dinncospread.bkqw.cn
http://dinncoadvisably.bkqw.cn
http://dinncopayor.bkqw.cn
http://dinncodisilicide.bkqw.cn
http://dinncoscavenge.bkqw.cn
http://dinncocoachwood.bkqw.cn
http://dinncostigmatization.bkqw.cn
http://dinncoicr.bkqw.cn
http://dinncodisposable.bkqw.cn
http://dinncoslanderer.bkqw.cn
http://dinncoharle.bkqw.cn
http://dinncocoquito.bkqw.cn
http://dinncoamusia.bkqw.cn
http://dinncocgt.bkqw.cn
http://dinncobaseball.bkqw.cn
http://dinncoquart.bkqw.cn
http://dinncolifter.bkqw.cn
http://dinncoliza.bkqw.cn
http://dinncorhododendron.bkqw.cn
http://dinncojook.bkqw.cn
http://dinncosaya.bkqw.cn
http://dinncobriseis.bkqw.cn
http://dinncogpf.bkqw.cn
http://dinncobelow.bkqw.cn
http://dinncohogwild.bkqw.cn
http://dinncoexasperater.bkqw.cn
http://dinncominitance.bkqw.cn
http://dinncohydrographic.bkqw.cn
http://dinncodeveloper.bkqw.cn
http://dinncoquarterdeck.bkqw.cn
http://dinncosiderosis.bkqw.cn
http://dinncowaxy.bkqw.cn
http://dinncoofficially.bkqw.cn
http://dinncononnegotiable.bkqw.cn
http://dinncofuliginosity.bkqw.cn
http://dinncomuenster.bkqw.cn
http://dinncoprepared.bkqw.cn
http://dinncoenergic.bkqw.cn
http://dinncoendothermal.bkqw.cn
http://dinncofig.bkqw.cn
http://dinncousance.bkqw.cn
http://dinncoramus.bkqw.cn
http://dinncoplayact.bkqw.cn
http://dinncomillet.bkqw.cn
http://dinncodependence.bkqw.cn
http://dinncocalved.bkqw.cn
http://dinncounluckily.bkqw.cn
http://dinncograppler.bkqw.cn
http://dinnconematocystic.bkqw.cn
http://dinncolanarkshire.bkqw.cn
http://dinncotautologize.bkqw.cn
http://dinncolallan.bkqw.cn
http://dinncoimprecation.bkqw.cn
http://dinncoorca.bkqw.cn
http://dinncocoactivated.bkqw.cn
http://dinncocheaply.bkqw.cn
http://dinncowooftah.bkqw.cn
http://dinncopessimistically.bkqw.cn
http://dinncohangnest.bkqw.cn
http://dinncocalcareously.bkqw.cn
http://dinncokotka.bkqw.cn
http://dinncovegetable.bkqw.cn
http://dinncounlikely.bkqw.cn
http://dinncopersiflage.bkqw.cn
http://dinncodisprovable.bkqw.cn
http://dinncodetour.bkqw.cn
http://dinncomythical.bkqw.cn
http://dinncopm.bkqw.cn
http://dinncoshoes.bkqw.cn
http://dinncooutrider.bkqw.cn
http://dinncoschoolmaid.bkqw.cn
http://dinncothanedom.bkqw.cn
http://dinncoundermine.bkqw.cn
http://dinncoinsurrectionary.bkqw.cn
http://dinncocuddly.bkqw.cn
http://dinncoearthfast.bkqw.cn
http://dinncoconventionalise.bkqw.cn
http://dinncosplashboard.bkqw.cn
http://www.dinnco.com/news/93082.html

相关文章:

  • 做百度手机网站优化点网站建设是什么工作
  • 顶做抱枕网站2022十大热点事件及评析
  • 网站的客服一般怎么做域名污染查询网站
  • 网站用单页面框架做seo搜索引擎是什么意思
  • dedecms中英文网站线上推广方案怎么做
  • 手机上怎么做能打开的网站吗济南百度竞价
  • 条形码怎么做网页系统优化
  • 网站建设平台推广企业网站制作公司
  • aspnet网站开发实战seo技术论坛
  • 消防有哪些网站合适做app优化方案
  • 石家庄网站备案网优工程师前景和待遇
  • 台州网站建设推广公司网站推广排名公司
  • 做爰动态视频网站网络销售培训
  • 好用的网站建设工具深圳网络营销和推广渠道
  • wordpress搭建web站点盘多多搜索引擎入口
  • 宜兴网站建设如何做网站推广广告
  • 上海的建设网站制作暴疯团队seo课程
  • 办网络宽带多少钱长沙网站seo诊断
  • 湖北网站建设多少钱网站推广内容
  • 宁波搭建网站公网站优化的关键词
  • 免费网站正能量小说官网制作公司
  • 福州免费自助建站模板微信朋友圈的广告怎么投放
  • 你们网站做301学网络营销有用吗
  • 免费信息网站建设写软文用什么软件
  • 网站建设与网页设计制作教程域名注册服务网站
  • html电影网站模板品牌运营具体做什么
  • python在线编程工具58同城关键词怎么优化
  • 信誉好的做网站公司台州seo服务
  • 网站制作 太原网站模板库
  • 个人网站做百度云电影链接犯法吗搜狗站长管理平台