为了理解B树算法,我尝试用C风格的伪代码编写。我想B树算法就像一个链表,但有一个指针数组和一个整数,它具有数组长度的值。我对吗?下面是链表的伪代码和我对B树的理解。我用B-tree算法得到的问题是它只适用于第一代孩子。有谁知道出了什么问题?
提前感谢您的帮助!
链接列表:
struct node datatypes for content... struct node *next; struct node* head = NULL struct node* p = NULL struct node* n = NULL head = malloc(sizeof *head) head→next = malloc(sizeof(struct node)) p = head→next p→content = malloc(sizeof string) while (...) input content p→next = malloc(sizeof(struct node)) n = p→next n→content = malloc(sizeof content) p=n
B树:
struct node datatypes for content... int children struct node *next [children] struct node* head = NULL struct node* p = NULL struct node* n = NULL head = malloc(sizeof *head); int children = input a value for i in length of children head→next[i] = malloc(sizeof(struct node)); head→next = malloc(sizeof(struct node)); p = head→next; p→content = malloc(sizeof content); while (...) input content p→next = malloc(sizeof(struct node)) n = p→next; n→children = input a value for i in length of children p→next[i] = malloc(sizeof(struct node)) p→content = malloc(sizeof content) p=n