Tag: 二叉搜索树

为什么这个搜索函数会返回一个指向指针的指针?

#ifndef _BST_H_ /* Returns negative (leftright). */ typedef int comparator(void* left, void* right); struct bst_node { void* data; struct bst_node* left; struct bst_node* right; }; struct bst_node* new_node(void* data); void free_node(struct bst_node* node); struct bst_node** search(struct bst_node** root, comparator compare, void* data); void insert(struct bst_node** root, comparator compare, void* data); void delete(struct bst_node** node); #endif […]

C – 使用后序遍历释放二叉树的内存

我想使用后序遍历删除二叉树 。 这意味着应首先删除树的左侧部分, 然后删除右侧的树,然后在后面的第二个函数中删除整个树并释放内存 。 我不允许更改函数的参数,只能使用它的内部: #include #include #include #include “telefonbuch.h” static inline bstree * create_node(unsigned long phone, char * name) { bstree * newNode = (bstree *) malloc(sizeof(bstree)); newNode->key.phone = phone; strcpy(newNode->key.name, name); newNode->left = NULL; newNode->right = NULL; return newNode; } void bst_insert_node(bstree * bst, unsigned long phone, char * name) { if […]