基于c实现排序二叉树转为双向链表,无需重新再创建一个双向链表结构体,直接对树的指针操作。
代码:
#include <stdlib.h>
#include <stdio.h>
typedef struct tree
{
int nValue;
struct tree *pLeft;
struct tree *pRight;
}BST;
void AddNode(BST **pTree, int num)
{
BST *pTemp = (BST*)malloc(sizeof(BST));
pTemp->nValue = num;
pTemp->pLeft = NULL;
pTemp->pRight = NULL;
if(*pTree == NULL)
{
*pTree = pTemp;
return;
}
BST *pNode = *pTree;
while(pNode != NULL)