Answered step by step
Verified Expert Solution
Question
1 Approved Answer
implement a B-tree on disk by using above codes in C language #define MAXDEG 6 typedef struct BTREE_NODE_5 *BTREE_NODE; typedef struct BTREE_NODE_5 { int n;
implement a B-tree on disk by using above codes in C language
#define MAXDEG 6 typedef struct BTREE_NODE_5 *BTREE_NODE; typedef struct BTREE_NODE_5 { int n; unsigned int *key; BTREE_NODE *child; } BTREE_NODE_t[1]; typedef struct BTREE_5 #BTREE; typedef struct BTREE S { BTREE_NODE root; } BTREE_t[1]; BTREE btree_init() { BTREE bt = (BTREE) malloc(sizeof(BTREE_D)); bt->root = NULL; return bt; } BTREE_NODE btree_node_init() { BTREE_NODE node = (BTREE_NODE) malloc(sizeof(BTREE_NODE_D)); node->key = (unsigned int *) malloc(sizeof(unsigned int) * (MAXDEG - 1)); node->child = (BTREE_NODE *) malloc(sizeof(BTREE_NODE) + MAXDEG); node->n = 0; return node; } void swap(void *a, void *b) { int temp = *(int *)a; *(int *)a = *(int *)b; *(int *)b = temp; } void sort (BTREE_NODE node) { int i, j; for(i = 0; i n - 1; i++) { for(j = 0; j n - i - 1; j++) { if(node->key[j] > node->key [j+1]) { | swap(&node->key[j], &node->key [j+1]); } } void create_btree (BTREE_NODE root, unsigned int *key) { int i, j; for(i = MAXDEG - 1; i key[j] && added == e) { int keys = root->child[j]->n; if (keys child[j]->key[keys] = key[i]; root->child[j]->n++; sort(root->child[j]); added = 1; }else{ printf("Input error "); } } if (key[i] > root->key [4] && added == 0) { int keys = root->child[5]->n; if (keys child[5]->key[keys] = key[i]; root->child[5] ->n++; sort(root->child[5]); added = 1; }else{ printf("Input error "); } void print_btree (BTREE_NODE root) { int i, j; for(i = 0; i child[i]->keyil); if(i key[i]); } } int main(void) { BTREE btree = btree_init(); BTREE_NODE root = btree->root; unsigned int key [35] = { 25, 45, 70, 90, 100, 17, 34, 19, 26, 59, 41, 99, 38, 105, 75, 91, 110, 9, 50, 55, 80, 81, 95, 112, 40, 5, 60, 118, 120, 85, 99, 88, 68, 93, 24 }; root = btree_node_init(); int i, j, ki for(i = ; i key[i] = key[i]; } for(i = ; i child[i] = btree_node_init(); } create_btree(root, key); print_btree(root); int minkey = ceil(MAXDEG/2) - 1; unsigned int delete[21] = {9, 17, 19, 5, 110, 112, 105, 120, 100, 85, 81, 75, 80, 88, 68, 70, 34, 40, 25, 118, 90}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started