Doubt about simple chaining in c

Asked

Viewed 164 times

3

I wanted to know why removal processes in threads have two pointers set to next

like this given example

void 
remove (celula *p)
{
celula *lixo;
lixo = p->prox;
p->prox = lixo->prox;
free (lixo);
}

because there is always something like "p->Prox = garbage->Prox;"? could you explain to me thank you

1 answer

3


Write down

p->prox = lixo->prox;

is the same thing as

p->prox = p->prox->prox;

You do this so you can remove the middle item.

Ex: imagine the list 4 5 6

The 4 is the p and the 5 is the lixo

The lixo->prox is the 6

In doing p->prox = lixo->prox I’m telling you that 4->prox = 6, then I can remove the 5 now that the list will not break.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.