using namespace std;
#include
Template
The class SeqStack
{
Private:
T data [100];
Int top;
Public:
SeqStack (void)
{
Top=0;
};
~ SeqStack (void) {};
Void Push (const T& Item)
{
If (top==100)
{
Cout & lt; <"The stack is full" & lt;
}
Data [top]=item;
Top++;
}
T Pop (void)
{
If (top==0)
{
Cout & lt; <"The stack is empty" & lt;
}
Top -;
The return data [top];
}
T GetTop (void) const
{
If (top==0)
{
Cout & lt; <"The stack is empty" & lt;
}
The return data [top - 1);
}
Int NotEmpty (void) const
{
Return (top!=0);
}
};
Template
The class BiTreeNode
{
Private:
BiTreeNode
BiTreeNode
Public:
T data;
BiTreeNode
~ BiTreeNode
BiTreeNode
BiTreeNode
};
Template
BiTreeNode
{
BiTreeNode
P=new BiTreeNode
return p;
}
Template
Void PreOrder (BiTreeNode
{
SeqStack
Stack. Push (t - & gt; The data);
While (stack. NotEmpty ())
{
If (t - & gt; Right ()!=NULL)
Stack. Push (t - & gt; Right () - & gt; The data);
If (t - & gt; The Left ()!=NULL)
Stack. Push (t - & gt; The Left () - & gt; The data);
}
}
Template
Void Visit (T data) {cout & lt;
{
BiTreeNode
G=GetTreeNode (" g ");
D=GetTreeNode (' d ', null, g);
B=GetTreeNode (' b, d);
E=GetTreeNode (' e ');
F=GetTreeNode (" f ");
C=GetTreeNode (' c, e, f);
Root=GetTreeNode (' A ', b, c);
}
Int main ()
{
BiTreeNode
MakeCharTree (root1);
PreOrder (root1, Visit);
return 0;
}
CodePudding user response:
While (stack. NotEmpty ())//stack, Push, will never be empty,
{
If (t - & gt; Right ()!=NULL)//t never change
Stack. Push (t - & gt; Right () - & gt; The data);
If (t - & gt; The Left ()!=NULL)
Stack. Push (t - & gt; The Left () - & gt; The data);
}
CodePudding user response:
Really thank you very muchCodePudding user response: