//已知二叉樹的前序和后序,創建該二叉樹
//并輸出該二叉樹的高和后序序列,第一行是測驗資料的組數N,
//后面為N組測驗資料,然后輸出高度和后序排列。
#include<iostream>
#include<string.h>
using namespace std;
const int maxsize = 100;
struct tree {
char data;
tree*rchild;
tree*lchild;
};
//二叉樹的創建
tree*creatBtree()
{
}
//前序
void qianxu(tree*Node)
{
if (Node == NULL)
return;
qianxu(Node->lchild);
qianxu(Node->rchild);
cout << Node->data;
}
//銷毀
void xiaohui(tree*root)
{
if (root == NULL)
return;
xiaohui(root->lchild);
xiaohui(root->rchild);
delete root;
}
//主函式
int main()
{
tree*root = NULL;
int N; //組數
char qianxu[maxsize]; //前序
char zhongxu[maxsize]; //中序
cin >> N; //輸入組數
cin >> qianxu>>" ">>zhongxu;//輸入前序和中序的二叉樹
int len = strlen(qianxu) - 1;
root = creatBtree();
xiaohui(root);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/245891.html
標籤:C++ 語言
上一篇:openssl1.1.1后結構體不暴露了,有些資料無法直接復制了,結構體我可以重新頭檔案補上嗎?用老版本方法new一個嗎。
下一篇:結構體,不太會求解
