非递归中序遍历

//非递归中序遍历
	//设置一个函数,该函数的作用是深入到最左侧子树但是不遍历
	void inOrder_Ii(TreeNode *bt,stack S) {
		while (bt)
		{
			S.push(bt);
			if(bt->lc)
			bt = bt->lc;
		}
	}
	void inOrder_I(TreeNode *bt, stack S) {
		while (true)
		{
			inOrder_Ii(bt, S);
			if (S.isEmpty())
				break;
			bt = S.pop();
			Visit(bt);
			bt = bt->rc;
		}
	}

  

猜你喜欢

转载自www.cnblogs.com/Royzzzzz/p/12968806.html