資料結構課設(二叉樹操作)

2021-08-14 08:36:10 字數 1140 閱讀 8664

一、設計內容和要求 

1.實現二叉樹的2種構造方法(輸入擴充套件二叉樹的前序遍歷序列構造二叉樹和已知二叉樹的前序、中序序列,構造此二叉樹)

2.對二叉樹進行前序、中序、後序和層次遍歷;

4.求二叉樹結點數、葉子結點和高度;

5.將二叉樹所有結點的左右子樹交換。

二、**

標頭檔案erchashu.h

#include #include#define num 100  

typedef char elemtype;

typedef struct binode*bitree;

原始檔:erchashu.cpp

#include"iostream.h"

#include"erchashu.h"

//先序建立乙個樹

void creattree(bitree &t)

}//先序遍歷

void preordertree(bitree t)

}//中序遍歷

void inordertree(bitree t)

}//後序遍歷

void lastordertree(bitree t)

}//層次遍歷

void levordertree(bitree t)

if(temp[i] ->rchild)

i++;

}//結點全部都在這個陣列裡面

for(t=0;t<=j;t++)

cout

}//計算深度

int depth(bitree t)

}//計算結點個數

int nodecount(bitree t)

//計算葉子結點

int leafcount(bitree t)

//交換左右子樹

void swapchild(bitree t)

}//主函式

資料結構課設 還原二叉樹

5 9 還原二叉樹 25分 給定一棵二叉樹的先序遍歷序列和中序遍歷序列,要求計算該二叉樹的高度。輸入首先給出正整數n le 50 為樹中結點總數。下面兩行先後給出先序和中序遍歷序列,均是長度為n的不包含重複英文本母 區別大小寫 的字串。輸出為乙個整數,即該二叉樹的高度。9 abdfghiec fdh...

資料結構課設 BST二叉排序樹

程式設計實現二叉排序樹的建立 插入 刪除和查詢 對於給定的這組數在二叉排序樹上進行查詢,給出兩種情況下的查詢成功和不成功時的asl bst include using namespace std const int maxn 1e5 typedef struct node bsnode,bstree...

資料結構 二叉樹 反轉二叉樹

include using namespace std define maxsize 1000 struct binary tree node class queue queue queue void queue push binary tree node btn binary tree node ...