#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
二叉树--
最新推荐文章于 2024-10-12 22:47:18 发布
这篇博客探讨了二叉树中节点变化如何影响其左右子树,特别是通过二分法构造节点时,每次节点变化都需要重新考虑内部类以保持结构正确。内容涉及到C语言和C++实现,以及算法的应用。
摘要由CSDN通过智能技术生成