Pergunta de entrevista da empresa Bloomberg

how to delete a node in a list

Resposta da entrevista

Sigiloso

5 de fev. de 2010

single linked list ? - then save pointer to next node, start from head and go to the node right before the node being deleted, and change it's "next" pointer to the one you saved. Now you can delete node. double linked list ? - no need to start from head, just reassign pointers in neighbor nodes properly to point to each other instead of to the node being deleted, and then delete the node. Of course, special care for first and last nodes, which have some NULL pointers.