0
我一个嵌套的结构是这样BST链接和案件没有工作
typedef struct Node_link {
struct Node_base *parent, *left, *right;
}Node_link;
typedef struct Node_base {
struct Node_link link[2];
}Node_base;
typedef struct Node{
struct Node_base base;
int size;
int *address;
}Node;
Node_base *head[2] ={NULL, NULL};
//头[0]商店int长度和头[1]它对应的地址
节点有权,左和父链接,都是嵌套的,例如node-> left-> link.parent = node。我必须维护所有链接(父,左和右)并删除节点。 我已经尝试了很多案例,仍然缺少一些。有人能告诉我什么情况下我需要使用?或者转介我一些材料?我搜索了很多,但没有成功。 我的插入功能如下:
Node_base * insert(Node_base *location, Node_base *n) {
if (head[0]==NULL)
head[0]=n;
else
{
if (location==NULL){
location=n;
return location;
}
else{
if(((Node *)n)->size < ((Node *)location)->size){
if(location->link[0].left==NULL)
{
location->link[0].left=n;
location->link[0].left->link[0].parent=location;
}
else
location->link[0].left=insert(location->link[0].left,n);
return location;
}
}
我已经为头相同的嵌套插入功能[1],其存储在插入头部节点的大小[0]。
你的结构看起来对我来说都是错的。你的插入函数不应该接受节点类型吗?为什么你甚至需要Node和Node_base之间的分离?为什么Node_base需要2个Node_link结构?这是给你什么部分,你自己实现了什么? –