hi,
i am trying to implement a B+ tree. There is no specification in the implementation so i am using arrays to implement the B+ tree. However, there is a problem that i encountered which is I cannot store the address of an array element in an another array element. it is purpose is reaching the childs. The other thing that i want to mention is that the bucket size of the b+ tree is not specific. It will be determined at the beginning of the program. For example it can store 4,6 or 10 data. it does not matter. Here is my code any help will be appreciated.
Thank you very much for your helps.
i am trying to implement a B+ tree. There is no specification in the implementation so i am using arrays to implement the B+ tree. However, there is a problem that i encountered which is I cannot store the address of an array element in an another array element. it is purpose is reaching the childs. The other thing that i want to mention is that the bucket size of the b+ tree is not specific. It will be determined at the beginning of the program. For example it can store 4,6 or 10 data. it does not matter. Here is my code any help will be appreciated.
Code:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define length(a) (sizeof a / sizeof a[0])
class Node{
public:
int count;
int leaf;
int *data;
int *pointer;
Node(int a){
leaf = 1;
count = 0;
data = new int[a];
pointer = new int[a+1];
}
};
void insert(Node *node, int data, int line){
Node *temp = new Node(line);
temp = node;
int i = 0;
if(temp->leaf == 1){
if(temp->count != line){
while(temp->data[i] < data){
i++;
}
for (int j = line; j > i; j--){
temp->data[j] = temp->data[j - 1];
}
temp->data[i] = data;
temp->count++;
}
else{
Node *temp2 = new Node(line);
Node *temp3 = new Node(line);
//temp->pointer[0] = &(temp2->data[0]);
//temp->pointer[1] = &(temp3->data[0]);
for(int i = 0; i < 2; i++){
temp2->data[i] = temp->data[i];
}
for(int i = 2; i < 5; i++){
temp3->data[i] = temp->data[i];
}
for(int i = 0; i < 4; i++){
temp->data[i] = 0;
}
temp->data[1]=temp3->data[1];
}
}
}
/*void deneme1(){
int a[3];
int *b[4];
b[1] = &(a[1]);
cout << b[1] << endl;
cout << &(a[1]) << endl;
}*/
int main(){
Node *temp = new Node(4);
Node *temp2 = new Node(4);
temp2->data[0] = 2;
cout << &temp2->data[0] << endl;
temp->pointer[0] = (int)(&temp2->data[0]);
//long x = &temp2->data[0];
//temp->pointer[0] = &temp2->data[0];
temp->data[0] = 3;
temp->data[1] = 12;
temp->data[2] = 45;
insert(temp,34,4);
for(int i = 0; i < 4; i++)
cout << temp->data[i] << endl;
cout << "benim " << temp->pointer[0] <<endl;
/*cout << sizeof(temp->data) << endl;
cout << length(temp->data) << endl;
cout << temp->data[0] << endl;
cout << temp->data[1] << endl;*/
return 0;
}
Comment