二叉排序樹

2021-07-16 12:54:16 字數 582 閱讀 6416

這道題的演算法思想主要是在建立排序二叉樹的基礎上,對兩個二叉樹進行比較,需要考慮幾種情況。

**如下:

#include

#include

#include

struct node;

struct node *createtree(struct node *root,int d)

else

else/*否則將其插入右子樹中*/

root->lchild=createtree(root->lchild,d);

}return root;

}int compare(struct node* root,struct node *root1)

int main()

while(n--)

if(compare(root,root1))

printf("yes\n");

else

printf("no\n");}}

return 0;

}

二叉排序樹

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