This document defines a B-tree data structure template in C++. It includes a BNode class to represent nodes in the B-tree and a BTree class that implements functions for operations on the B-tree like insertion, searching and printing the tree. The BNode class stores keys, child nodes and metadata. The BTree class implements functions for insertion that push new keys into nodes and split full nodes, as well as functions for searching keys and printing the structure of the tree.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
112 views4 pages
TAD Btree: Estructura de Datos II Página: 1
This document defines a B-tree data structure template in C++. It includes a BNode class to represent nodes in the B-tree and a BTree class that implements functions for operations on the B-tree like insertion, searching and printing the tree. The BNode class stores keys, child nodes and metadata. The BTree class implements functions for insertion that push new keys into nodes and split full nodes, as well as functions for searching keys and printing the structure of the tree.
Estructura de Datos II Pgina: M.Sc. Karim Guevara Puente de la Vega 2 template<class E> class BTree{ private: BNode<E> *root; int orden; bool FindNode(BNode<E> *,E, int *);
template <class E> void BTree<E>::insert(E cl){ int up; E median; BNode<E> *pnew,*nd; push(root,cl,&up,&median,&nd);
Estructura de Datos II Pgina: M.Sc. Karim Guevara Puente de la Vega 3 if(up){ pnew=new BNode<E>(orden); pnew->count=1; pnew->keys[0]=median; pnew->childs[0]=root; pnew->childs[1]=nd; root=pnew; } }
template <class E> void BTree<E>::dividedNode(BNode<E> *current,E cl,BNode<E> *rd, int k,E *median,BNode<E> **nuevo){ int i,posMdna; posMdna=(k<=orden/2)?orden/2:orden/2+1;
(*nuevo)=new BNode<E>(orden);
for(i=posMdna;i<orden-1;i++){ (*nuevo)->keys[i-posMdna]=current->keys[i]; (*nuevo)->childs[i-posMdna+1]=current->childs[i+1]; } Estructura de Datos II Pgina: M.Sc. Karim Guevara Puente de la Vega 4 (*nuevo)->count=(orden-1)-posMdna; current->count=posMdna;