文件名称:preorder_tree_stack
-
所属分类:
- 标签属性:
- 上传时间:2016-04-16
-
文件大小:1.38kb
-
已下载:0次
-
提 供 者:
-
相关连接:无下载说明:别用迅雷下载,失败请重下,重下不扣分!
介绍说明--下载内容来自于网络,使用问题请自行百度
二叉树非递归先序遍历,使用栈
一直往左走 root->left->left->left…->null,
由于是先序遍历,因此一遇到节点,便需要立即访问;
由于一直走到最左边后,需要逐步返回到父节点访问右节点,
因此必须有一个措施能够对节点序列回溯。
有两个办法:
1.用栈记忆:在访问途中将依次遇到的节点保存下来。由于节点出现次序与恢复次序是反序的,因此是一个先进后出结构,需要用栈。
2.节点增加指向父节点的指针:通过指向父节点的指针来回溯-Nonrecursive preorder binary tree, using the stack has been left to go root-> left-> left-> left ...-> null, as is the preorder, it encountered a node, we need immediate access as has come to the after the left, we need to gradually return to the parent node to access the right node, so there must be able to measure a sequence of nodes backtracking. There are two ways: 1. Stack Memory: The saved nodes sequentially encountered in the access way. Since the node order and restore order in reverse order, so that is a last-out structure, need to use the stack. 2. The node point increase pointer to the parent: by pointing a pointer to the parent node back
一直往左走 root->left->left->left…->null,
由于是先序遍历,因此一遇到节点,便需要立即访问;
由于一直走到最左边后,需要逐步返回到父节点访问右节点,
因此必须有一个措施能够对节点序列回溯。
有两个办法:
1.用栈记忆:在访问途中将依次遇到的节点保存下来。由于节点出现次序与恢复次序是反序的,因此是一个先进后出结构,需要用栈。
2.节点增加指向父节点的指针:通过指向父节点的指针来回溯-Nonrecursive preorder binary tree, using the stack has been left to go root-> left-> left-> left ...-> null, as is the preorder, it encountered a node, we need immediate access as has come to the after the left, we need to gradually return to the parent node to access the right node, so there must be able to measure a sequence of nodes backtracking. There are two ways: 1. Stack Memory: The saved nodes sequentially encountered in the access way. Since the node order and restore order in reverse order, so that is a last-out structure, need to use the stack. 2. The node point increase pointer to the parent: by pointing a pointer to the parent node back
(系统自动生成,下载前可以参看下载内容)
下载文件列表
preorder_tree_stack.cpp
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.