二叉排序樹

2021-06-15 05:17:58 字數 944 閱讀 7051

二叉排序樹的查詢、插入和刪除操作

#include using namespace std;

typedef int status;

#define ok 1

#define error 0

#define true 1

#define false 0

typedef struct bitnode bitnode , *bitree;

status searchbst( bitree t, int key, bitree f, bitree *p)

else if ( key == t->data )

else if ( key data)

return searchbst( t->lchild , key, t, p) ;

else

return searchbst( t->rchild, key, t , p);

}status insertbst ( bitree &t, int key)

return false;

}status delete( bitree& p)

else if ( p->lchild ==null )

else

p->data =s->data;

if (q!=p) q->rchild =s->lchild;

else q->lchild = s->lchild;

free( s);

} return true;

}status deletebst( bitree &t, int key)

}void printbst( bitree t)

}int main();

bitree t=null;

for( int i=0; i<10; i++){

insertbst( t, a[i]);

cout<

二叉排序樹

在複習資料結構,把這個東西總結一下。這種結構是動態查詢表,這種動態是相對靜態查詢 順序查詢,折半查詢,分塊查詢等 來說的。對於各種靜態鍊錶,要達到查詢複雜度為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 ...