先序遍历非递归遍历算法
void InOrderTraversal( BinTree BT ){
BinTree T BT;
Stack S = CreatStack( MaxSize );
while( T || !IsEmpty(S) ){
while(T){
printf(“%5d”, T->Data);
Push(S,T);
T = T->Left;
}
if(!IsEmpty(S)){
T = Pop(S);
T = T->Right;
}
}
}
中序遍历非递归遍历算法
void InOrderTraversal( BinTree BT ){
BinTree T=BT;
Stack S = CreatStack( MaxSize );
while( T || !IsEmpty(S) ){
while(T){
Push(S,T);
T = T->Left;
}
if(!IsEmpty(S)){
T = Pop(S);
printf(“%5d”, T->Data);
T = T->Right;
}
}
}
层序遍历算法
void BFSOrderTraversal ( BinTree BT ){
Queue Q; BinTree T;
if ( !BT )
return;
Q = CreatQueue( MaxSize );
AddQ( Q, BT );
while ( !IsEmptyQ( Q ) ) {
T = DeleteQ( Q );
printf(“%d\n”, T->Data);
if ( T->Left ) AddQ( Q, T->Left );
if ( T->Right ) AddQ( Q, T->Right );
}
}