#include <iostream>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
typedef struct BtNode
{
char data;
struct BtNode *lchild;
struct BtNode *rchild;
}BtNode, *Bitree;
typedef struct Node
{
Bitree p;
int degree;
}Node, *pNode;
int createBtTree( Bitree *head )
{
int ret = 0;
char ch;
cin >> ch;
if( '#' == ch )
{
*head = NULL;
return ret;
}
Bitree pNode = new BtNode;
pNode->data = ch;
pNode->lchild = NULL;
pNode->rchild = NULL;
*head = pNode;
createBtTree( &(*head)->lchild );
createBtTree( &(*head)->rchild );
return ret;
}
// 三种递归遍历
void preTravel( Bitree head )
{
if( head != NULL )
{
cout << head->data << ' ';
preTravel( head->lchild );
preTravel( head->rchild );
}
return;
}
void midTravel( Bitree head )
{
if( head != NULL )
{
midTrav
面试题27:二叉搜索树按中序遍历原地转换为双向链表
最新推荐文章于 2021-07-29 17:58:47 发布
本文介绍了如何将一个二叉搜索树原地转换为双向链表,通过中序遍历的方式,实现了递归和非递归两种方法,并提供了完整的C++代码示例。最后展示了双向链表的正向和反向打印结果。
摘要由CSDN通过智能技术生成