|
常用链接
留言簿(3)
随笔档案
搜索
最新评论
阅读排行榜
评论排行榜
Powered by: 博客园
模板提供:沪江博客
|
|
|
|
|
发新文章 |
|
|
#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<
|
|