- void InorderTraversal( BinTree BT )
- {
- if( BT ) {
- InorderTraversal( BT->Left );
- / * Access to BT is assumed here that the node is the print data * /
- the printf ( "% D" , BT-> the Data); / * assume integer data * /
- InorderTraversal( BT->Right );
- }
- }
- void PreorderTraversal( BinTree BT )
- {
- if( BT ) {
- printf("%d ", BT->Data );
- PreorderTraversal( BT->Left );
- PreorderTraversal( BT->Right );
- }
- }
- void PostorderTraversal( BinTree BT )
- {
- if( BT ) {
- PostorderTraversal( BT->Left );
- PostorderTraversal( BT->Right );
- printf("%d ", BT->Data);
- }
- }
- void LevelorderTraversal ( BinTree BT )
- {
- Queue Q;
- BinTree T;
- IF (! BT) return ; / * if empty tree directly return * /
- CreatQueue = Q (); / * Create an empty queue Q * /
- AddQ( Q, BT );
- while ( !IsEmpty(Q) ) {
- T = DeleteQ( Q );
- the printf ( "% D" , T-> the Data); / * remove the access node queue * /
- if ( T->Left ) AddQ( Q, T->Left );
- if ( T->Right ) AddQ( Q, T->Right );
- }
- }
Four kinds of binary tree traversal chain store
Guess you like
Origin www.cnblogs.com/lzdxh027/p/11323534.html
Ranking