I have the following function:
Nodo * insertOrder(Nodo *L,Nodo *nv){
//11,1,50,7,5
if(L==NULL){
return nv;
}
if(nv->id < L->id){
return (insertFirst(L, nv));
}
int c=0;
Nodo *aux2=L;
Nodo *aux=NULL;
while(L!=NULL){
if(nv->id < L->id){
c=1;
aux->nseg=nv;
nv->nant=aux;
L->nant=nv;
nv->nseg=L;
}
aux=L;//guarda o elemento anterior
L=L->nseg;
}
if(c==0){
aux->nseg=nv;
nv->nant=aux;
}
return aux2;
}
I do not understand why the function mentioned does not insert in order and I have interpreted the code several times.
For 11,1,50,7,5
Returns: 1 - > 5 - > 50