【发布时间】:2013-06-09 17:34:33
【问题描述】:
我将二叉树定义为搜索表。树是一个链表二叉树,节点是这样的
typedef struct node{
int key;
char *buf;
...
}node_t;
typedef table_t node_t *; 所以我有像
这样的功能 insert(table_t table, node_t node)
search(table_t table, node_t node)
现在我有多个键,比如
typedef struct node{
int key1;
int key2;
char *buf;
...
}node_t;
我想拥有如下功能:
search_by_key1(table_t table, node_t node, int key1)
search_by_key2(table_t table, node_t node, int key2)
确实,它就像一个数据库,我可以在任何键中搜索一个项目。
有源代码示例吗?我正在使用 linux C 谢谢!
【问题讨论】:
-
有了多个键,你不需要多棵树吗?否则,哪个键决定哪个节点在左边,哪个在右边?
-
是的,如果我有两个钥匙,我想也许我需要制作两棵树,有什么解决方法吗?