测试程序

#include <stdio.h>
//二叉树的类型定义 
typedef struct BiNode{
	char data;
	BiNode* LChild;
	BiNode* RChild;
}BiNode,*BiTree;
//队列的类型定义 
typedef struct Node{
	char data;
	struct Node* next;
}LinkQueueNode;

typedef struct{
	LinkQueueNode *front;
	LinkQueueNode *rear;
}LinkQueue;

//初始化队
int InitQueue(LinkQueue *q)
{
	q->front=(LinkQueueNode*)malloc(sizeof(LinkQueueNode));
	if(q->front!=NULL)
	{
		q->rear=q->front;
		q->front->next=NULL;
		return(1);
	}
	else return(0);
} 
//入队操作
int EnterQueue(LinkQueue *q,char x)
{
	LinkQueueNode *NewNode;
	NewNode=(LinkQueueNode*)malloc(sizeof(LinkQueueNode));
	if(NewNode!=NULL)
	{
		NewNode->data=x;
		NewNode->next=NULL;
		q->rear->next=NewNode;
		q->rear=NewNode;
		return(1);
	}
	else return(0);
} 

//出队操作
int DeleteQueue(LinkQueue *q,char *x)
{
	LinkQueueNode *p;
	if(q->front==q->rear)
	 return(0);
	p=q->front->rear;
	q->front->next=p->next;
	if(q->rear==p)
	 q->rear=q->front;
	*x=p->data;
	free(q);
	return(1)
} 
//按层序打印二叉树 
void printInLines(BiTree* T)
{
	LinkQueue q;
	InitQueue(&q);
	if(T==NULL)
	 return;
	EnterQueue(&q,T);//根节点进队
	while(isEmpty(&q))
	{
		//出对保存队头并访问 
		BiNode *s;
		DeleteQueue(&q,s);
		printf("%c",s->data);
		//将出队结点的左子树根入队
		EnterQueue(&q,s->LChild);
		//将出队结点的右子树根入队
		EnterQueue(&q,s->RChild); 
	} 
	
}
//建立二叉树 
createBiTree(BiTree* T)
{
	char ch;
	scanf("%c",&ch);
	if(ch=' ')
	 *T=NULL;
	else
	{
		*T=(BiTree)malloc(sizeof(BiNode));
		if(!*T)
		{
			return;
		}
		createBiTree(T->LChild);
		createBiTree(T->RChild);
	}
}
void main()
{
	BiTree T;
	createBiTree(&T);
	 
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值