When is doubly linked list more efficient than singly linked list?

后端 未结 6 977
萌比男神i
萌比男神i 2020-12-07 14:09

In an interview today I got asked the question.

Apart from answering reversing the list and both forward and backward traversal there was something \"fundamental\"

6条回答
  •  天命终不由人
    2020-12-07 14:31

    If you are going to delete an element in a linked list, you will need to link the previous element to the next element. With a doubly linked list you have ready access to both elements because you have links to both of them.

    This assumes that you already have a pointer to the element you need to delete and there is no searching involved.

提交回复
热议问题