#include <stack>
using namespace std;
class Node
{
public:
Node* left;
Node* right;
int data;
};
void inOrder(Node* r)
{
stack<Node*> s;
s.push(r);
while(!s.empty())
{
Node*p;
// to the most left
while((p=s.top()) && p)
{
s.push(p->left);
}
// remove null node
s.pop();
if(!s.empty())
{
p = s.top();
s.pop();
// visist p->data here
// move right one step
s.push(p->right);
}
}
}
非递归写法放在这里做参考。