c++ - B-Tree Node Spliting Techniques -


i've stumbled upon problem whilst doing dsa (data structures , algorithms) homework. i'm said implement b-tree insertion , search algorithms. far goes, search working correctly, i'm having trouble implementing insertion function. logic behind b-tree node-splitting algorithm. pseudocode/c-style come following:

    #define d 2     #define dd 2*d      typedef btreenode* btree;     typedef struct node     {         int keys[dd];  //d == 2 , dd == 2*d;         btree pointers[dd+1];         int index; //used iterate throught "keys" array     }btreenode;      void splitnode(btree* parent, btree* child1, btree* child2)     {         //copies content splitted node children         (*child1)->key[0] = (*parent)->key[0];         (*child1)->key[1] = (*parent)->key[1];         (*child2)->key[0] = (*parent)->key[2];         (*child2)->key[1] = (*parent)->key[3];         (*child1)->index = 1;         (*child2)->index = 1;         //"clears" parent node data         for(int = 0; i<dd; i++) (*parent)->key[i] = -1;         for(int = 0; i<dd+1; i++) (*parent)->pointers[i] = null         //fixed pointers children         (*parent)->index = 0;         //the line bellow taken out creating new node  didn't have there.         //(*parent)->key[(*parent)->index] = newnode(); // newnode() function allocs , inserts new key need insert.         (*parent)->pointers[index] = (*child1);         (*parent)->pointers[index+1] = (*child2);     } 

i'm sure i'm messing pointers, i'm not sure what. appreciated. maybe need little bit more study on b-tree subject? must add while can use basic input/output c++, need use c-style structs.

thanks

you don't need create new node here. you've apparently created 2 new child nodes. have here after populating children make parent point 2 children, via copy of first key in each of them, , adjust key count two. don't need set parent keys -1 either.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -