Doubts about simple chaining in c

3

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

As this example given

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

Because there's always something like "p-> prox = junk-> prox;"? Could you please explain to me?

    
asked by anonymous 18.04.2017 / 21:44

1 answer

3

Write

p->prox = lixo->prox;

is the same as

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

You do this to remove the item from the middle.

Ex: imagine the list 4 5 6

The 4 is the p and the 5 is the lixo

The lixo->prox is the 6

When doing p->prox = lixo->prox I'm talking about 4->prox = 6 , so I can remove 5 now that list will not break.

    
18.04.2017 / 21:58