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

优秀网站seo全称是什么意思

优秀网站,seo全称是什么意思,公司做网站广告语,制作网站能赚钱吗利用递归来遍历树,实际的递归中隐式利用了栈,在此我们可以直接模拟递归中栈的调用。在后序遍历中从左向右依次先序遍历该每个以子节点为根的子树,然后先遍历节点本身。在这里的栈模拟中比较难处理的在于从当前节点 u 的子节点 v1 返回时&…

利用递归来遍历树,实际的递归中隐式利用了栈,在此我们可以直接模拟递归中栈的调用。在后序遍历中从左向右依次先序遍历该每个以子节点为根的子树,然后先遍历节点本身。在这里的栈模拟中比较难处理的在于从当前节点 u 的子节点 v1 返回时,此时需要处理节点 u 的下一个节点 v2 ,此时需要记录当前已经遍历完成哪些子节点,才能找到下一个需要遍历的节点。在二叉树树中因为只有左右两个子节点,因此比较方便处理,在 N 叉树中由于有多个子节点,因此使用哈希表记录当前节点 u 已经访问过哪些子节点。

每次入栈时都将当前。节点的 u 的第一个子节点压入栈中,直到当前节点为空节点为止;

每次查看栈顶元素 p ,如果节点 p 的子节点已经全部访问过,则记录当前节点的值,并将节点 p 的从栈中弹出,并从哈希表中移除,表示该以该节点的子树已经全部遍历过;如果当前节点 p 的子节点还有未遍历的,则将当前节点的 p 的下一个未访问的节点压入到栈中,重复上述的入栈操作。

代码

Java

class Solution {public List<Integer> postorder(Node root) {List<Integer> res = new ArrayList<Integer>();if (root == null) {return res;}Map<Node, Integer> map = new HashMap<Node, Integer>();Deque<Node> stack = new ArrayDeque<Node>();Node node = root;while (!stack.isEmpty() || node != null) {while (node != null) {stack.push(node);List<Node> children = node.children;if (children != null && children.size() > 0) {map.put(node, 0);node = children.get(0);} else {node = null;}}node = stack.peek();int index = map.getOrDefault(node, -1) + 1;List<Node> children = node.children;if (children != null && children.size() > index) {map.put(node, index);node = children.get(index);} else {res.add(node.val);stack.pop();map.remove(node);node = null;}}return res;}
}

C++

class Solution {
public:vector<int> postorder(Node* root) {vector<int> res;if (root == nullptr) {return res;}unordered_map<Node *, int> cnt;stack<Node *> st;Node * node = root;while (!st.empty() || node != nullptr) {while (node != nullptr) {st.emplace(node);if (node->children.size() > 0) {cnt[node] = 0;node = node->children[0];} else {node = nullptr;}         }node = st.top();int index = cnt.count(node) ? (cnt[node] + 1) : 0;if (index < node->children.size()) {cnt[node] = index;node = node->children[index];} else {res.emplace_back(node->val);st.pop();cnt.erase(node);node = nullptr;}}return res;}
};

C#

public class Solution {public IList<int> Postorder(Node root) {IList<int> res = new List<int>();if (root == null) {return res;}Dictionary<Node, int> dictionary = new Dictionary<Node, int>();Stack<Node> stack = new Stack<Node>();Node node = root;while (stack.Count > 0 || node != null) {while (node != null) {stack.Push(node);IList<Node> childrenList = node.children;if (childrenList != null && childrenList.Count > 0) {dictionary.Add(node, 0);node = childrenList[0];} else {node = null;}}node = stack.Peek();int index = (dictionary.ContainsKey(node) ? dictionary[node] : -1) + 1;IList<Node> children = node.children;if (children != null && children.Count > index) {dictionary[node] = index;node = children[index];} else {res.Add(node.val);stack.Pop();dictionary.Remove(node);node = null;}}return res;}
}     

好了,今天的文章分享就到这里了,希望对大家的学习有帮助哦! 

http://www.dtcms.com/wzjs/143339.html

相关文章:

  • 小型网站的建设与开发营销网站建设网站开发
  • 杭州建设监理行业协会工具seo
  • 门户网站介绍优秀网页设计赏析
  • 杭州正规制作网站公司吗福州seo按天付费
  • 洛阳做网站查询网站流量的网址
  • 建设手机网站哪个平台比较好seo外链工具软件
  • 帮人做彩票网站seo外链发布工具
  • 北京移动官方网站郑州网站seo优化公司
  • 深圳o2o网站建设2023年最新新闻摘抄
  • 网站模板怎么使用深圳网络推广平台
  • 网站推广策划报告航空航天邵阳seo排名
  • 南山区公司网站制作肇庆seo外包公司
  • 51aspx源码seo如何优化网站步骤
  • 备案里的网站名称百度电话怎么转人工
  • 帝国生成网站地图东莞seo网络推广专
  • 如何做购物网站小程序开发公司前十名
  • 网站建设与管理的未来规划方案个人模板建站
  • 私服广告网站谁做的网站展示型推广
  • 甘洛网站建设湖南seo网站多少钱
  • 一家公司做两个网站吗企业网站seo服务
  • 用手机制作app用哪个软件关键词优化公司推荐
  • 网站建设功能报价表网站测速
  • 网站建设设计开发公司软件推广是什么工作
  • 长城集团建设有限公司网站网站怎么优化关键词
  • 高端网站建设高端网站建设专家市场推广专员
  • 做彩票网站需要什么收钱的郑州做网站推广哪家好
  • 响应式网站建设济南口碑营销是什么意思
  • 专业的上海网站建设公司排名2024小学生时事新闻十条
  • 手机网站 cms舆情视频
  • 网站建设费用评估重庆seo培训