2D linked list Java
Introduction to Java Doubly Linked ListJava Doubly Linked List is a type of Linked List where each node apart from storing data has two links. The first link points to the previous node and the other link points to the next node of the list. Doubly Linked List, also abbreviated as DLL is much like a Single Linked List. Both Linked lists contain a pointer to the next node and a data field to represent the actual value to be stored in the node. The main difference is that DLL contains a pointer to the previous node in the list i.e. nodes in DLL are aware of both the previous and the next node. In this article, we will have a look at Doubly Linked List in Java, explore few examples, and get to know its Implementation. Syntax: Start Your Free Software Development Course Web development, programming languages, Software testing & others There is no particular syntax for the Doubly Linked list in Java, but we will see How to declare the Doubly Linked List in Java. Before looking into a declaration of Doubly Linked List, let us see the Concept behind the implementation of Doubly Linked List. Node in Double Linked List:
Here Prev Node and Next Node are pointers to previous and next elements of node respectively. Data is the actual element where data is stored. Below are some of the important terms we need to understand, Prev: Each link of linked list has a link to the previous node called Prev. Next: Each link of linked list has a link to the next node called Next Popular Course in this category Java Training (40 Courses, 29 Projects, 4 Quizzes)40 Online Courses | 29 Hands-on Projects | 285+ Hours | Verifiable Certificate of Completion | Lifetime Access | 4 Quizzes with Solutions 4.8 (12,334 ratings) Course Price View Course Related Courses JavaScript Training Program (39 Courses, 23 Projects, 4 Quizzes)jQuery Training (8 Courses, 5 Projects)Free Java Online CourseJavaFX Training (1 Courses)Link: Each link of linked list can store data, known as element. Linked List: It contains the connection link to the first link and the last link. Algorithm:
Declaration of Node for Doubly Linked List in Java: class Node { As we can see there is an extra declaration or a reference(Node prev) in the case of Doubly Linked List. Basic Operations of Doubly Linked List: Below are the basic operations available for Doubly Linked List, Insertion: Adding an element at the beginning of the linked list Deletion: Deleting an element at the beginning of the linked list Insert After: Adding an element after an item of linked list Insert Last: Adding an element to the end of the linked list Delete Last: Deleting an element at the end of linked list Delete: Deleting an element from the linked list using a key. Display forward: Displaying complete list in forward manner Display backward: Displaying complete list in backward manner Example 1: Declaration of Node and Adding nodes to Display in Doubly Linked List public class DLL { Output: So here we are creating a Node class to declare a Doubly Linked list and displaying the values of DLL. Example #2: Doubly Linked List, delete at beginning of the linked list and display.public class DLL { Output: So here, the node is deleted at the beginning of the linked list i.e. Node 3 is deleted/ removed. DLL can be traversed in forwarding and backward directions. Delete operation in DLL can be more efficient if the node pointer to be deleted is given. Every Node in DLL requires extra space for the previous pointer. All operations require an extra pointer to be maintained. With this, we shall conclude our topic Java Doubly Linked List. We have seen What Java Doubly Linked List is and how is it implemented in Java programming with few examples. We have also seen Algorithm for Doubly Linked List and have listed out few operations applicable to DLL. We have implemented Insertion and delete at first operations, likewise, there are other operations also available which you can work on. Recommended ArticlesThis is a guide to Java Doubly Linked List. Here we discuss Introduction, syntax, how is it implemented in Java programming with examples with code implementation. You may also have a look at the following articles to learn more
All in One Software Development Bundle (600+ Courses, 50+ projects) 600+ Online Courses 50+ projects 3000+ Hours Verifiable Certificates Lifetime Access Learn More 0 Shares Share Tweet Share |