#include #define maxsize 100 class BitTree { public: int data; BitTree LChild(); BitTree RChild(); int flag; BitTree(){ data=0; flag=0; } BitTree(int d){ data=d; flag=0; }; protected: private: }; BitTree BitTree::LChild(){ BitTree d(1); return d; } BitTree BitTree::RChild(){ BitTree d(1); return d; } struct SqStack { BitTree Elem[maxsize]; int top; SqStack(){ top=0; }; }; class Stack { public: Stack(SqStack sq); virtual ~Stack(); void push(BitTree bit); BitTree pop(); bool isEmpty(); protected: private: SqStack sq; }; Stack::Stack(SqStack sq){ Stack::sq=sq; } void Stack::push(BitTree bit){ sq.Elem[sq.top]=bit; sq.top++; } BitTree Stack::pop(){ BitTree temp; temp=sq.Elem[sq.top]; sq.top--; return temp; } bool Stack::isEmpty(){ return sq.top?true:false; } Stack::~Stack(){ } //中序遍历 非递归 void LVRList(BitTree t){ SqStack *s; s=new SqStack(); Stack stackD(*s); BitTree p=t; while (&p!=NULL ||!stackD.isEmpty()) { while (&p!=NULL) { stackD.push(p); p=p.LChild(); } if (!stackD.isEmpty()) { p=stackD.pop(); cout<
发表于 2007-05-06 10:35 刘甘泉 阅读(604) 评论(0)  编辑  收藏