日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数据结构树的基本操作_树的各类基本操作(数据结构)

發(fā)布時間:2023/12/3 编程问答 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据结构树的基本操作_树的各类基本操作(数据结构) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#include "iostream"

/*

輸入:ABC DE G F

ABC DE G F

*/

#include "bits/stdc++.h"

using namespace std;

typedef struct bitnode

{

char data;

bitnode *lchild,*rchild;

} *bintree;

bintree creatree(bintree &root)//先序創(chuàng)建樹

{

char a=getchar();

if(a==' ')

{

root=NULL;

return root;

}

else

{

root=(bintree)malloc(sizeof(bitnode));

root->data=a;

creatree(root->lchild);

creatree(root->rchild);

return root;

}

}

void PreOrderTraverse(bintree root)//InOrderTraverse中序 PostOrderTraverse 倒序

{

if(root==NULL)

{

return ;

}

else

{

PreOrderTraverse(root->lchild);

PreOrderTraverse(root->rchild);

cout<data<

}

}

int CountDegreeOne(bintree root)//度為一節(jié)點的個數(shù)

{

if(root==NULL)

return 0;

else

{

int a=CountDegreeOne(root->lchild);

int b=CountDegreeOne(root->rchild);

if(root->lchild&&!root->rchild||root->rchild&&!root->lchild)

return a+b+1;

else

return a+b;

}

}

int DeepTree(bintree root)//樹的深度

{

if(root==NULL)

return 0;

else

{

int a=DeepTree(root->lchild);

int b=DeepTree(root->rchild);

if(a>=b)

return a+1;

else

return b+1;

}

}

int same(bintree root,bintree root1)//判斷兩棵樹是否相同

{

if(root&&!root1||root1&&!root||!root&&!root1)

{

return 0;

}

else

{

if(root->data==root1->data)

{

int a=same(root->lchild,root1->lchild);

int b=same(root->rchild,root1->rchild);

if(a==b==1)

return 1;

}

else

return 0;

}

}

int main()

{

bintree root;

bintree root1;

creatree(root);

getchar();

creatree(root1);

PreOrderTraverse(root);

cout<

cout<

if(same(root,root1))

cout<

else

cout<

return 0;

}

總結(jié)

以上是生活随笔為你收集整理的数据结构树的基本操作_树的各类基本操作(数据结构)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。