乙個簡單的資料結構舉例 二叉樹及

2021-07-02 23:18:49 字數 1455 閱讀 4799

binarytree

//頭檔名:btree.h

#include "stdafx.h"

#include "iostream"

using namespace std;

class btree ;

//cpp名:btree.cpp

#include "stdafx.h"

#include "btree.h"

btree::btree(int data)

btree::btree()

// binarytree.cpp : 定義控制台應用程式的入口點。

//#include "stdafx.h"

#include "btree.h"

#include "ctime"

void insert(btree*,btree*);

void display(btree *head);

void firstdisplay(btree *p);

void lastdisplay(btree *head);

btree *node=null;

int _tmain(int argc, _tchar* argv)

f1:

cout << endl << endl << "前序遍歷結果:";

firstdisplay(node);

cout << endl << endl << "中序遍歷結果:";

display(node);

cout << endl << endl << "後序遍歷結果:";

lastdisplay(node);

cout << endl << endl;

continue; }

f2:cout << endl << endl << "前序遍歷結果:";

firstdisplay(node);

cout << endl << endl << "中序遍歷結果:";

display(node);

cout << endl << endl << "後序遍歷結果:";

lastdisplay(node);

cout << endl<} }

else continue; }

return 0; }

void insert(btree *father,btree *son)

if (father->data > son->data)

else

} else if (father->data < son->data)

else

} else

} //中序遍歷

void display(btree *p)

//前序遍歷

void firstdisplay(btree *p)

//後序遍歷

void lastdisplay(btree *p)

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

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 ...

《資料結構》 二叉樹

二叉樹 是 n個結點的有限集,它或為空集,或由乙個根結點及兩棵互不相交的 分別稱為該根的左子樹和右子樹的二叉樹組成。二叉樹不是樹的特殊情況,這是兩種不同的資料結構 它與無序樹和度為 2的有序樹不同。二叉樹的性質 1 二叉樹第 i層上的結點數最多為 2 i 1 2 深度為 k的二叉樹至多有 2 k 1...

資料結構 二叉樹

1.二叉樹 二叉樹是一種特殊結構的樹,每個節點中最多有兩個子節點,如圖1所示 圖1 二叉樹 在圖1中的二叉樹裡,a c有兩個子節點,b d有乙個子節點。對於二叉樹還有圖2中的以下情況 圖2 二叉樹的特殊情況 在博文中還介紹了滿二叉樹和完全二叉樹還有其他的特殊二叉樹。2.二叉樹的實現 有兩種實現方式,...