Im trying to implement a btree. I don't have any error in compiling, but when I run my code I have some weird runtime error. It says something like: MALLOC c:3096: sYsmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned......
why is this happening? I already tested that the problem is when I call crear_nodo(), which creates a new nodo, and returns me the pointer of the new node
btree* D=crear_nodo(aux, temp); //runtime error!
please help. I need to find the problem :'(
Bellow is the structure of the tree:
typedef struct nodo{
int clave[3];
struct nodo* rama[4];
struct nodo* padre;
int color;
int peso; //controls the number of keys in the node
}nodo;
typedef struct nodo* btree;
This is my code for the insertion method:
void dividir_nodo(btree* hoja, int dato, int pos){
btree* x;
int temp; //keeps the fouth key
int mediana; //saves the medium key which is going up, by default is clave[2] of the repositioned keys
if (pos==1){ //key is in clave[0]
temp=(*hoja)->clave[2];
(*hoja)->clave[2]=(*hoja)->clave[1];
(*hoja)->clave[1]=(*hoja)->clave[0];
(*hoja)->clave[0]=dato;
mediana=(*hoja)->clave[2];
}
//int pos tells me the position of the new key in the node
//--------------------------------//
btree* D=crear_nodo(aux, temp); //creation of the right node, which contains the clave[2] of *hoja
//--------------------------------//
(*hoja)->clave[2]=NULL; //modifies node hoja to eliminate the key that is now in node D
if ((*hoja)->padre==NULL){ //if *hoja is the tree root, creates a new node for the mediana, which is going up
btree* P=crear_nodo(aux, mediana)
//setting up the pointers:
(*hoja)->padre=*P;
(*D)->padre=*P;
(*P)->rama[0]=*hoja;
(*P)->rama[1]=*D;
}
else //if hoja->padre already exists, just moves up the mediana
subir_mediana(hoja, D, &(*hoja)->padre, mediana);
}
this is the method which creates a new node:
btree* crear_nodo(btree* r, int dato){
*r= (nodo*)malloc(sizeof(btree));
(*r)->clave[0]=dato;
(*r)->clave[1]=NULL;
(*r)->clave[2]=NULL;
(*r)->rama[0]=NULL;
(*r)->rama[1]=NULL;
(*r)->rama[2]=NULL;
(*r)->peso=1;
(*r)->color=0;
return r;
}
aux and hoja are global variables.
NOTE: I used aux just for testing, I get the same error if I do: btree* D=crear_nodo(D, temp);
Google says that this happends because Im trying to allocate something of size 0, but I already check temp and mediana, they are not cero. Otherwise, if I just do: btree D=new (nodo);
I get the same error. Help please. T__T