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

后端 未结 6 981
萌比男神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:27

    Doubly Linked list is more effective than the Singly linked list when the location of the element to be deleted is given.Because it is required to operate on "4" pointers only & "2" when the element to be deleted is at the first node or at the last node.
    
    
    struct  Node {
    
           int  Value;
           struct Node  *Fwd;
           struct Node  *Bwd;
    );
    
    
    Only the below line of code will be enough to delete the element ,If the element to be deleted is not in the first or last node.
    
    X->Bwd->Fwd = X->Fwd; X->Fwd->Bwd = X->Bwd ;
    

提交回复
热议问题