double-ended lists

Linked Lists: Double-Ended Lists Example

Double-ended lists is similar to ordinary linked list, but it has one additional feature compared to ordinary linked list. It provides a reference to the last link as well as to the first link.

Supported Operations:

  • insertFirst() – inserting link at front of the linked list
  • insertLast() – inserting link at rear of the linked list
  • deleteFirst() – deleting link at front of the linked list
  • displayList() – display items in the linked list

Advantage of last link:

The reference to the last link enables you to insert link directly at the end of the list as well as the beginning. You can also insert link at the end of single-ended list by iterating through the entire list until you reach the end, but this approach is not efficient.

Note: Don’t confuse the double-ended list with doubly linked list

Application of Double-Ended Linked List

In Double-ended linked list you have access to the end of the list as well as beginning of the list. In situation like while implementing queue double-ended list would be useful in handling certain situations efficiently.

Double-Ended List Example

Output

Recommended Posts

References

Leave a Reply

avatar
  Subscribe  
Notify of