golang 算法课 非递归前序&中序遍历模板

func inorder_preorder(root *TreeNode) {
	stack := make([]*TreeNode, 0, 0)
	for len(stack) != 0 || root !=nil{
		for root != nil{
			//TODO 先序遍历 DO
			stack = append(stack, root)
			root = root.Left
		}

		root = stack[len(stack) -1]
		stack = stack[:len(stack) -1]
		//TODO 中序遍历 DO

		root = root.Right
	}
}

你可能感兴趣的:(学习笔记)