[英]Printing the keys of B+ Tree
我想打印B +树的键,就像它在C中的样子一样,例如以下形式
| 12 |20| 30|
5|9|11| |12|17|_| |20|27|26| |30|-|-|
上面的树是order(扇出)4。顶部节点是树节点。 任何算法或伪代码将不胜感激。
编辑
数据结构,我正在实现树。以及实现树的代码。 当我尝试打印树时,在行Enqueue(tempNode->pointers[i]);
分段错误Enqueue(tempNode->pointers[i]);
模块printBplus(root)
typedef struct bplus{
void ** pointers; /*These are the array of pointers that each tree node contains*/
int * keys; /*These are the array of keys in each tree node*/
struct bplus * parent; /*This the pointer to the parent tree node */
bool is_Leaf; /*To check if the node is leaf*/
int num_Keys; /*This keeps track the number of active keys in the node */
struct bplus * next ; /*This is the pointer to next level tree,used for queuing and dequeing node*/
} *bplus, bplus_node;
入队和出队:
void Enqueue(bplus a){
bplus bplusTemp;
if (queue == NULL) { //bplus queue=NULL is global variable
queue = a
queue->next = NULL;
}
else {
bplusTemp = queue;
while(bplusTemp->next != NULL) {
bplusTemp = bplusTemp->next;
}
bplusTemp->next = a;
bplusNew->next = NULL;
}
}
bplus Dequeue( void ) {
bplus bplusTemp = queue;
queue = queue->next;
bplusTemp->next = NULL;
return bplusTemp;
}
打印模块
void PrintBplus(bplus root){
int i;
bplus tempNode;
queue = NULL;
Enqueue(root); /*It enques the root*/
if(root === leaf)
print the keys associated with it
while(queue != NULL){
tempNode = Dequeue();
for(i=0; i < tempNode->num_Keys; i++)
printf("%d,",root->keys[i]);
if(tempNode->is_Leaf == false){
for(i=0; i <= tempNode->num_Keys; i++)
Enqueue(tempNode->pointers[i]);
}
}
我假设通过“它的实际外观”来表示一个漂亮的图,例如它们如何在教科书中打印b树。
如果要从最一般的角度解决树,按树的实际外观打印树是一个非常简单的问题。 问题包括:
我在数据结构课程中花了一段时间研究它,但从未想到一个完全令人满意的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.