#include #include #include #include typedef int datatype;
typedef struct node * bstptr;
struct node
;bstptr parent1;
bstptr parent2;
void addnodetobst(bstptr *root, datatype key)
else if((*root)->data > key)
else if((*root)->data < key)
else }
void preorder(const bstptr root)
}void inorder(const bstptr root)
}void postorder(const bstptr root)
}bstptr maxnode(bstptr tree)
return tree;
}bstptr minnode(bstptr tree)
return tree;
}bstptr search(bstptr tree, datatype key)
else if(tree->data > key)
else
}return null;
}void deletenode(bstptr *tree, datatype key)
if(!(node->lchild) && !(node->rchild))
else if(node->lchild && !(node->rchild))
else if(node->rchild && !(node->lchild))
else
else if(tmp->lchild && !(tmp->rchild))
else if(tmp->rchild && !(tmp->lchild))
}}int main(void)
資料結構之二叉查詢樹
針對二叉查詢樹的操作 增刪改查 的時間和樹的高度成正比,比如都有10個節點的乙個樹,樹高為4和樹高為10的操作時間肯定是不同的,這個時間實際上是o lgn 二叉查詢樹的期望的樹高是lgn,從而基本動態集合的操作平均時間為 lgn 通常二叉查詢樹基於鍊錶實現,每個節點儲存左,右子節點,如果想更方便的實...
資料結構之二叉查詢樹
二叉樹成為二叉查詢樹的性質是,對於樹種的每個節點x,他的左子樹中的所有關鍵字的值均小於x的關鍵字的值,而他的右子樹中的所有關鍵字的值均大於x的關鍵字的值。這意味著,該樹的所有元素均可以是用某種統一的方式排序。tree.h pragma once we define the binary tree.s...
資料結構之二叉查詢樹
二叉查詢樹 binary search tree 又被稱為二叉搜尋樹。設x為二叉查詢樹中的乙個結點,x節點包含關鍵字key,節點x的key值記為 ke y x k ey x 如果y是x的左子樹中的乙個結點,則 ke y y ke y x k ey y ke y x 如果y是x的右子樹的乙個結點,則 ...