Я бы хотел напечатать ключи дерева B + так, как оно выглядит в C. Например, в следующей форме
| 12 |20| 30|
5|9|11| |12|17|_| |20|27|26| |30|-|-|
Вышеуказанное дерево имеет порядок (разветвление) 4. Верхний узелузел дерева.Любой алгоритм или псевдокод будет высоко оценен.
РЕДАКТИРОВАТЬ
структура данных я реализую дерево. И код для реализации дерева.Когда я пытаюсь распечатать дерево, я получаю ошибку сегментации в строке 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]);
}
}