二元樹與二元搜尋樹系列教學文目錄
【部分程式碼】遞迴方式插入節點
struct bstNode *insert (struct bstNode *node, int input) {
if (node != NULL) {
if (input >= node->key) {
node->rnode = insert(node->rnode, input);
} else {
node->lnode = insert(node->lnode, input);
}
} else {
node = malloc(sizeof(struct bstNode));
node->key = input;
node->lnode = NULL;
node->rnode = NULL;
}
return node;
}
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
Pinterest
Email