Bootstrap

6-2 二叉树的遍历 (25 分)-数据结构第5章

void InorderTraversal( BinTree BT )
{
	if(!BT)return;
	InorderTraversal(BT->Left);
	printf(" %c",BT->Data);
	InorderTraversal(BT->Right);
}
void PreorderTraversal( BinTree BT )
{
	if(!BT)return;
	printf(" %c",BT->Data);
	PreorderTraversal(BT->Left);
	PreorderTraversal(BT->Right);
}
void PostorderTraversal( BinTree BT )
{
	if(!BT)return;
	PostorderTraversal(BT->Left);
	PostorderTraversal(BT->Right);
	printf(" %c",BT->Data);
}
void LevelorderTraversal( BinTree BT )
{
	BinTree q[100000];
	int front = -1 , rear = -1;
	if(BT==NULL)return;
	q[++rear] = BT;
	while(front!=rear)
	{
		BinTree b = q[++front];
		printf(" %c",b->Data) ;
		if(b->Left!=NULL)q[++rear] = b->Left;
		if(b->Right!=NULL)q[++rear] = b->Right;
	}	
	
}

 

;