二叉排序樹

2021-06-18 17:01:06 字數 2900 閱讀 5093

二叉排序樹(binary sort tree)又稱二叉查詢樹。 它或者是一棵空樹;或者是具有下列性質的二叉樹:

(1)若左子樹不空,則左子樹上所有結點的值均小於它的根結點的值;

(2)若右子樹不空,則右子樹上所有結點的值均大於它的根結點的值;

(3)左、右子樹也分別為二叉排序樹;

--如果有兩個相等的元素, 可根據情況 自定義位置。。!

實現了, 二叉排序樹的 構造(遞迴和 非遞迴)、查詢、插入。

[cpp]view plain

copy

print?

//#include "sortedtree.h"

#include 

using

namespace std;  

struct node  

node(int num):data(num),left(null),right(null){}  

};  

class binarysorttree  

;  binarysorttree::binarysorttree(int a,int len):rootnode(null)  

}  void binarysorttree::insertnode_loop(int num)  

node * prootnode = rootnode;   

node *pnode = new node(num);  

//待插入的節點 小於根節點則 插入到 左子樹

二叉排序樹

在複習資料結構,把這個東西總結一下。這種結構是動態查詢表,這種動態是相對靜態查詢 順序查詢,折半查詢,分塊查詢等 來說的。對於各種靜態鍊錶,要達到查詢複雜度為o logn 必須要求有序 而要使插入刪除複雜度為o 1 必須是鍊錶儲存。動態查詢表就可以同時滿足這兩者。動態查詢表的特點是表結構本身在查詢過...

二叉排序樹

name 二叉排序樹相關操作 author unimen date 2011 10 8 13 14 21 刪除結點比較麻煩,總結如下 4大種情況 1 結點p無右孩子 將該點的左孩子變為其在雙親中的同位孩子 1 p為其雙親的左孩子時將其的左孩子變為雙親的左孩子 2 p為其雙親的右孩子時將其的左孩子變為...

二叉排序樹

include include include include struct tree node void insert node struct tree node int void pre order struct tree node void in order struct tree node ...