Status ListTraverse(LinkList L,Status (*vist)(int ,Link )){ /*依次对L的每个元素调用函数vist()一旦vist失败,则操作失败 */ Link tmp = L.head->next; int i = 1; while(tmp != NULL) { if (FALSE==vist(i,tmp)) return FALSE ; else tmp=tmp->next; i++; } return OK; }
void BinNode<T>::travPre(VST& visit) { BinNode<T*> x = this; std::stack<BinNodePosi(T)> s; if (x) s.push(x); while(!s.empty()) { vist(s.top()); x = s.top(); s.pop(); if(x->rChild) s.push(x->rChild); if(x->lChild) s.push(x->lChild); } }
void BinNode<T>::travIn(VST& visit) { BinNode<T*> x = this; std::stack<BinNodePosi(T)> s; while(x && !s.empty) { while(x) { if(x->lChild) { s.push(x->lChild); x = x->lChild; } } x = s.top(); vist(x); s.pop(); x = x->rChild; } }