层序遍历的核心思想是什么?有关于我使用的层序遍历的代码放在后面了,求解答

img

裁判测试程序样例
#include
#include

typedef char ElementType;
typedef struct TNode *Position;
typedef Position BinTree;
struct TNode{
ElementType Data;
BinTree Left;
BinTree Right;
};

BinTree CreatBinTree(); /* 实现细节忽略 */
void InorderTraversal( BinTree BT );
void PreorderTraversal( BinTree BT );
void PostorderTraversal( BinTree BT );
void LevelorderTraversal( BinTree BT );

int main()
{
BinTree BT = CreatBinTree();
printf("Inorder:"); InorderTraversal(BT); printf("\n");
printf("Preorder:"); PreorderTraversal(BT); printf("\n");
printf("Postorder:"); PostorderTraversal(BT); printf("\n");
printf("Levelorder:"); LevelorderTraversal(BT); printf("\n");
return 0;
}
/* 你的代码将被嵌在这里 */

img

我的代码
//中序遍历
void InorderTraversal( BinTree BT )
{
if(BT)
{
InorderTraversal(BT->Left);
printf(" %c",BT->Data);
InorderTraversal(BT->Right);
}
}
//前序遍历
void PreorderTraversal( BinTree BT )
{
if(BT)
{
printf(" %c",BT->Data);
PreorderTraversal(BT->Left);
PreorderTraversal(BT->Right);
}
}
//后序遍历
void PostorderTraversal( BinTree BT )
{
if(BT)
{
PostorderTraversal(BT->Left);
PostorderTraversal(BT->Right);
printf(" %c",BT->Data);
}
}
//层序遍历
void LevelorderTraversal( BinTree BT )
{
int i=0,j=0;
BinTree ptr[100]={NULL},ptr1=NULL;
if(BT!=NULL)
{
ptr[i++]=BT;
while(i>j)
{
ptr1=ptr[j++];
printf(" %c",ptr1->Data);
if(ptr1->Left!=NULL) ptr[i++]=ptr1->Left;
if(ptr1->Right!=NULL) ptr[i++]=ptr1->Right;
}
}
}