/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
type Stack struct {
Parr [1000]*TreeNode
Index int
}
func(s *Stack) IsEmpty() bool {
if s.Index <= 0 {
return true
}else {
return false
}
}
func(s *Stack) Push(p *TreeNode) {
s.Parr[s.Index] = p
s.Index = s.Index + 1
}
func(s *Stack) Pop() (*TreeNode){
if s.Index > 0 {
s.Index = s.Index - 1
return s.Parr[s.Index]
}else {
return nil
}
}
func inorderTraversal(root *TreeNode) []int {
rsp := make([]int, 0)
if nil == root {
return rsp
}
stack := Stack{}
for ; !stack.IsEmpty() || root != nil; {
for ; root != nil; {
stack.Push(root)
root = root.Left
}
if !stack.IsEmpty() {
root = stack.Pop()
rsp = append(rsp, root.Val)
root = root.Right
}
}
return rsp
}