首页 > 其他 > 详细

非递归前序遍历

时间:2020-05-26 23:20:07      阅读:55      评论:0      收藏:0      [点我收藏+]
        //非递归前序遍历
	//设置一个函数,该函数的作用是深入左子树同时遍历,用栈保存右子树
	void preOreder_Ii(TreeNode *bt, stack S) {
		while (bt)
		{
			Visit(bt);
			if(bt->rc)
			S.push(bt->rc);
			bt = bt->lc;
		}
	}
	void preOreder_I(TreeNode *bt) {
		stack S;
		while (true) {
			preOreder_Ii(bt, S); 
			if (S.isEmpty())
				break;
			bt = S.pop();
		}
	}

  

非递归前序遍历

原文:https://www.cnblogs.com/Royzzzzz/p/12968739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!