因为时间实在是十分的紧,所有的代码都是伪码。
#include <iostream>
#include <stack>
using namespace std;
typedef struct BinNode {
int data;
struct BinNode * lchild;
struct BinNode * rchild;
} BinNode;
typedef BinNode* p;
p root;
stack<p> s;
void tran_lchild_chain(p x) {
while(x) {
//visit(x)
if(x->rchild) s.push(x->rchild);
x = x->lchild;
}
}
void tran_pre_new_idea() {
s.push(root);
p x = NULL;
while(x) {
if(s.empty()) break;
x = s.top(); s.pop();
tran_lchild_chain(x);
}
}