#include<stdio.h>
#include<stdlib.h>
typedef struct LinkNode
{
BiTree data;
struct LinkNode* next;
}LinkNode;
typedef struct LinkQue
{
LinkNode* front,*rear;
}LinkQue;
bool InitLQ(LinkQue &Q)
{
Q.front = (LinkNode*)malloc(sizeof(LinkNode));
Q.front->next = NULL;
Q.rear = Q.front;
return true;
}
bool DeQue(LinkQue &Q,BiTree &x)
{
if(Q.front==Q.rear)
return false;
LinkNode* s;
s = Q.front->next;
x=s->data;
Q.front->next=s->next;
if(s==Q.rear)
{
Q.rear=Q.front;
}
free(s);
return true;
}
bool EnQue(LinkQue &Q,BiTree x)
{
LinkNode *S = (LinkNode*)malloc(sizeof(LinkNode));
S->data = x;
S->next = NULL;
Q.rear->next = S;
Q.rear = S;
return true;
}
typedef struct BiNode
{
int data;
struct BiNode *lchild,*rchild;
}BiTnode,*BiTree;
void LevelOder(BiTree T)
{
LinkQue L;
InitLQ(L);
BiTree p ;
EnQue(L,p);
while(!IsEmpty(L))
{
DeQue(L,p);
printf("%d",p->data);
if(p->lchild!=NULL)
EnQue(L,p->lchild);
if(p->rchild!=NULL)
EnQue(L,p->rchild);
}
}
void main(void)
{
}
|