There are two problems with Singly Linked Lists. One we can’t get back to the beginning of the list from the end. Second, we can’t go backwards through the list. Therefore, doubly linked lists and circular linked lists were invented.

Doubly linked list is a common variation on linked lists is to have two references to other nodes within each node: one to the next node on the list, and one to the previous node. —Doubly-linked lists make some operations, such as deleting a tail node, more efficient.

Properties

  • —Allow sequential access to the list in both directions.
  • —Each element points to Next element and Previous element

Adding element to Doubly Linked List—

When adding a node to the list at a given index, the following steps must be taken:

  • Advance through the list to the node just before the one with the proper index.
  • Create a new node, and attach it to the nodes that should precede and follow it.

There are 2 ways you can add a new element to an existing linked list.

1. addFirst Method: It adds an element before a specified (existing) element.

2. addLast Method: It adds an element after a specified (existing) element.

Removing element from Doubly Linked List

—When removing a node from the list at a given index, the following steps must be taken:

  • Advance through the list to the node with the proper index.
  • Detach it from the nodes that used to precede and follow it.

There 3 ways you can remove an element from a list.

1. Remove a middle element

2. Remove head element

3. Remove the only element 

Tagged with: C/C++ languageData structures
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.