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

在線編譯二叉樹

發布時間: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);
}

閱讀全文

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

熱點內容
中國銀行app賬號怎麼登錄 瀏覽:861
安卓手機icloud雲伺服器地址 瀏覽:795
加密門禁如何寫到小米手機 瀏覽:163
java靜態方法的多線程 瀏覽:259
CAXAXp下載打不開要加密 瀏覽:238
開鎖pdf 瀏覽:83
python可視化奶茶 瀏覽:218
命令方字幕 瀏覽:591
蘋果手機如何連接ipad伺服器 瀏覽:975
列印矩陣java 瀏覽:393
如何雙開一個不能雙開的app 瀏覽:528
抖音喜歡加密了怎麼打開 瀏覽:385
mysql命令行顯示表 瀏覽:364
國防離我們源碼200字 瀏覽:777
vmwaretoolslinux 瀏覽:93
命令方塊生存放不了嗎 瀏覽:700
程序員入門很難嗎 瀏覽:103
70後程序員照片 瀏覽:194
一個普通程序員能幹多久 瀏覽:936
adobe的PDF轉換器 瀏覽:862