#include<stdio.h>
#include<stdlib.h>
typedef char ElemType;//为了树中放任意类型元素方便
typedef struct node_t
{//第一步:
ElemType c;
struct node_t *pright;
struct node_t *pleft;
}Node_t, *pNode_t;
//queue[kju]
//辅助队列数据结构,每个元素放的树中元素节点地址值,能快速定树中节点
typedef struct queue_t{
pNode_t insertPos;
struct queue_t *pNext;
}Queue_t, *pQueue_t;
void preOrder(pNode_t);
void buildBinaryTree(pNode_t *treeRoot, pQueue_t *queHead, pQueue_t *queTail, ElemType val){
pNode_t treeNew = (pNode_t)calloc(1, sizeof(Node_t));
pQueue_t queNew = (pQueue_t)calloc(1,sizeof(Queue_t));
pQueue_t queCur = *queHead;
treeNew->c = val;
queNew->insertPos = treeNew;
if (NULL == *treeRoot){
*treeRoot = treeNew;
*queHead = queNew;
*queTail = queNew;
}
else{
(*queTail)->pNext = queNew;
*queTail = queNew;
if (NULL == queCur->insertPos->pleft){
queCur->insertPos->pleft = treeNew;
}
else if(NULL == queCur->insertPos->pright){//漏了if(NULL == queNew->insertPos-&
C语言实现:qsort排序指针数组间接完成对链表的排序
最新推荐文章于 2023-11-15 11:18:49 发布
本文详细介绍了如何使用C语言构建二叉树,并通过预定义的队列辅助数据结构来快速定位树中的节点。此外,还实现了前序遍历算法,展示了如何逐个访问树中的元素。

最低0.47元/天 解锁文章
912

被折叠的 条评论
为什么被折叠?



