while(p || st.size()!=0) { //沿着左孩子方向走到最左下。 while(p) { st.push(p); p = p->left; } //get the top element of the stack p = st.top(); //如果p没有右孩子或者其右孩子刚刚被访问过 if(p->right == NULL || p->right == pre) { //visit this element and then pop it cout << "visit: " << p->data << endl; st.pop(); pre = p; p = NULL;