普通树的一些操作,杂记

普通树的一些操作,杂记



 //树的数据结构,静态实现  struct Node{ typename data; //数据域 vector child; //指针域,存放所有子结点的下标  }node[maxn]; //结点数组,maxn为结点上限个数 //新建一个树结点,但是,一般考试中设计树(非二叉树)的考查时, //一般都给出了结点的编号,我们可以把给定的编号直接作为node数组的 //下标来使用。  int index=0; int new_node(int v) { node[index].data =v; node[index].child.clear(); //清空子结点 return index++; //返回结点下标,并令index自增  } //如果题目中不涉及结点的数据域只需要数的结构 //简化为: vector<int> child[maxn] //树的先根遍历 void preorder(int root) { printf("%d ",node[root].data); //访问当前结点 for(int i=0;i<node[root].child.size();i++) { preorder(node[root].child[i]); //递归访问结点root的所有子结点  } } //树的层序遍历 void layerorder(int root) { queue<int> queue; queue.push(root); while(!queue.empty()) { int front=queue.front(); printf("%d ",node[front].data); //访问当前结点的数据 queue.pop(); for(int i=0;i<node[front].child.size();i++) { queue.push(node[front].child[i]); //将当前结点的所有子结点如队列  } } } //带 层 的树的数据结构静态实现 struct Node{ int layer; //记录层号  int data; vector<int> child; }node[maxn]; //新的树的 层序遍历 void layerorder(int root) { queue<int> queue; queue.push(root); node[root].layer=1; while(!queue.empty()) { int front=queue.front(); //取出队首元素  printf("%d ",node[front].data); queue.pop(); for(int i=0;i<node[front].child.size();i++) { int child=node[front].child[i]; node[child].layer=node[front].layer+1; queue.push(child); //将当前结点的所有子结点入队列  } } } 
全部评论

相关推荐

09-16 14:43
已编辑
江娱互动_研发_客户端开发
背景&nbsp;双一流本硕&nbsp;双非大圆满&nbsp;只找游戏开发相关的岗位。&nbsp;8&nbsp;月初开始秋招到现在&nbsp;投了四五十家吧,&nbsp;目前两&nbsp;offer,&nbsp;不打算继续投了,把剩下的流程走完就开始沉淀了。目前两&nbsp;offer&nbsp;一个是网易互娱测开&nbsp;base&nbsp;广州,一个是江娱互动客户端开发&nbsp;base&nbsp;北京。应该确定网易这个了,说实话北京这个我挺想去的,这家的产品和工作氛围我了解了也不错,是那种踏实做事的,可惜我是广东人。网易的测开是调剂的二志愿,看了下有内部转岗机会,所以打算后面找个时间提前实习,沉淀下再做一个&nbsp;demo&nbsp;作品,写一些&nbsp;shader,增强下图形学渲染的能力,再学点编辑器开发。看到时候内部转岗或者春招继续投客户端开发这样。后面还能再动摇的话应该就灵犀或者腾子了吧(假如这两家确认的是客户端开发岗的话)。-----------------------补下timeline网易互娱&nbsp;测开&nbsp;8.2笔试&nbsp;&nbsp;8.21&nbsp;技术面&nbsp;&nbsp;8.29&nbsp;leader&amp;HRBP面(终面)&nbsp;9.8&nbsp;录用审核(之前一直显示面试中)9.14&nbsp;oc江娱互动&nbsp;客户端开发&nbsp;8.29主程面&nbsp;9.3&nbsp;制作人面&nbsp;9.5&nbsp;BOSS面&nbsp;9.11&nbsp;口头OC&nbsp;9.15&nbsp;正式offer后面考虑了一下&nbsp;&nbsp;感觉还是能走开发就开发吧,测开不太感兴趣,要内部活水转岗还要满1年才能申请。。
点赞 评论 收藏
分享
10-16 15:48
算法工程师
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务