Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any doubly linked list implementation in Java?

I see JDK implementation of LinkedList internally contains Node inner class, which contains the address to next and previous.

So my doubt isn't LinkedList in java a doubly linked list. If not, why?

And how to implement our own doubly linked list?

like image 335
Avinash Jethy Avatar asked Jul 12 '15 08:07

Avinash Jethy


People also ask

Does Java have built in doubly linked list?

Yes, LinkedList is a doubly linked list, as the Javadoc mentions : Doubly-linked list implementation of the List and Deque interfaces. Implements all optional list operations, and permits all elements (including null).

Is Java LinkedList doubly linked?

The Java LinkedList APIThe LinkedList class in the Java Collection API library is a doubly linked list implementation of the List and Deque interfaces that form a generic data structure. The LinkedList object allows null to be one of the elements of the list along with its support of all optional list operations.

Is it possible to implement a doubly linked list?

Is it possible to create a doubly linked list using only one pointer with every node. (B) Yes, possible by storing XOR of addresses of previous and next nodes.


1 Answers

Yes, LinkedList is a doubly linked list, as the Javadoc mentions :

Doubly-linked list implementation of the List and Deque interfaces. Implements all optional list operations, and permits all elements (including null).

All of the operations perform as could be expected for a doubly-linked list. Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.

like image 154
Eran Avatar answered Sep 19 '22 12:09

Eran