導航:首頁 > 源碼編譯 > 在線編譯二叉樹

在線編譯二叉樹

發布時間:2023-09-26 11:54:45

㈠ 二叉樹c語言實現

#include<iostream.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
char data;
struct node *lchild,*rchild;//
}BiTNode,*BiTree;
void CreatBiTree(BiTree &T)
{
char ch;
ch=getchar();
if (ch == ' ')
T = 0;
else {
T=(BiTNode*)malloc(sizeof(BiTNode));
T->data=ch;//生成根節點
CreatBiTree(T->lchild);//構造左子樹
CreatBiTree(T->rchild);//構造右子樹
}
}
void preorder(BiTree T)//前序遍歷
{
if (T!=NULL){
printf ("%c",T->data);
preorder(T->lchild);
preorder(T->rchild);
}
}
void inorder(BiTree T)//中序遍歷
{
if (T!=NULL){
inorder(T->lchild);
printf ("%c",T->data);
inorder(T->rchild);
}
}
void postorder(BiTree T)//後序遍歷
{
if (T!=NULL){
postorder(T->lchild);
postorder(T->rchild);
printf ("%c",T->data);
}
}
void main ()
{
cout<<"請輸入要創建的二叉樹包括空格:"<<endl ;
BiTree T;
CreatBiTree(T);//創建二叉樹
cout<<"前序遍歷的結果為:"<<endl;
preorder(T);
cout<<endl;
cout<<"中序遍歷的結果為:"<<endl;
inorder(T);
cout<<endl;
cout<<"後序遍歷的結果為:"<<endl;
postorder(T);
}

閱讀全文

與在線編譯二叉樹相關的資料

熱點內容
應用被加密但不知道密碼 瀏覽:584
百度雲黑馬android 瀏覽:773
java格式化long 瀏覽:893
汽車如何加密文檔 瀏覽:625
公司理財第9版pdf 瀏覽:524
微信個人表情在文件夾 瀏覽:833
加密狗密碼監控 瀏覽:437
重載發生在編譯時 瀏覽:417
怎麼用app買東西 瀏覽:532
ug後處理多坐標宏命令 瀏覽:34
性教育pdf 瀏覽:863
解釋方式編譯方式名詞解釋 瀏覽:851
wrf編譯出現module 瀏覽:616
插入演算法最基礎代碼 瀏覽:27
powermill和ug編程 瀏覽:843
vf命令按鈕 瀏覽:283
塗鴉王國app怎麼 瀏覽:37
oppo如何關閉加密應用震動 瀏覽:802
直接拍PDF 瀏覽:580
伺服器有一個自動分配的ip地址嗎 瀏覽:470