二叉树--

这篇博客探讨了二叉树中节点变化如何影响其左右子树,特别是通过二分法构造节点时,每次节点变化都需要重新考虑内部类以保持结构正确。内容涉及到C语言和C++实现,以及算法的应用。
摘要由CSDN通过智能技术生成
#include <stdio.h>
#include <malloc.h>
 
#define QUEUE_SIZE 5
 
/**
 * Binary tree node.
 */
typedef struct BTNode{
	char element;
	BTNode* left;
	BTNode* right;
}BTNode, *BTNodePtr;
 
/**
 * A queue with a number of pointers.
 */
typedef struct BTNodePtrQueue{
	BTNodePtr* nodePtrs;
	int front;
	int rear;
}BTNodePtrQueue, *QueuePtr;
 
/**
 * Initialize the queue.
 */
QueuePtr initQueue(){
	QueuePtr resultQueuePtr = (QueuePtr)malloc(sizeof(struct BTNodePtrQueue));
	resultQueuePtr->nodePtrs = (BTNodePtr*)malloc(QUEUE_SIZE * sizeof(BTNodePtr));
	resultQueuePtr->front = 0;
	resultQueuePtr->rear = 1;
	return resultQueuePtr;
}//Of initQueue
 
/**
 * Is the queue empty?
 */
bool isQueueEmpty(QueuePtr paraQueuePtr){
	if ((paraQueuePtr->front + 1) % QUEUE_SIZE == paraQueuePtr->rear) {
		return true;
	}//Of if
 
	return false;
}//Of isQueueEmpty
 
/**
 * Add a pointer to the queue.
 */
void enqueue(QueuePtr paraQueuePtr, BTNodePtr paraBTNodePtr){
	printf("front = %d, rear = %d.\r\n", paraQueuePtr->front, paraQueuePtr->rear);
	if ((paraQueuePtr->rear + 1) % QUEUE_SIZE == paraQueuePtr->front % QUEUE_SIZE) {
		printf("Error, trying to enqueue %c. queue full.\r\n", paraBTNodePtr->element);
		retu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值