0
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 enter in order and I have interpreted the code several times.
For 11,1,50,7,5
Return: 1 -> 5 -> 50
Missing a break; inside the while cycle if
– manuel
"For 11,1,50,7,5 " - what does each of these values mean ? " Returns: 1 -> 5 -> 50" - and what was supposed to return ? What are the two function parameters
insertOrder
? How the structure was definedNodo
and their typedefs ?– Isac
the arrow is the pointer to the next element:1->5->7->11->50. Only one break was missing inside the if. I already solved the problem
– manuel
If you have already solved the problem the ideal is to put the solution as a properly detailed answer so that a person with a similar problem can also solve it.
– Isac