KEMBAR78
Doubly Linked List | PDF
0% found this document useful (0 votes)
26 views1 page

Doubly Linked List

The document contains a Java implementation of a doubly linked list with a Node class that includes methods for displaying the list in both forward and backward directions. The main class creates a linked list with nodes containing characters 'A' to 'E' and demonstrates the display methods. The linked list is properly linked with previous and next references for each node.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Doubly Linked List

The document contains a Java implementation of a doubly linked list with a Node class that includes methods for displaying the list in both forward and backward directions. The main class creates a linked list with nodes containing characters 'A' to 'E' and demonstrates the display methods. The linked list is properly linked with previous and next references for each node.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

package datastructure;

class Node
{
Node prev;
char data;
Node next;
public Node(char x)
{
this.prev=null;
this.data=x;
this.next=null;
}
public void displayForward(Node head)
{
Node current=head;
while(current!=null)
{
System.out.print(current.data+" ");
current=current.next;
}
}
public void displayBackword(Node tail)
{
Node current=tail;
while(current!=null)
{
System.out.print(current.data+" ");
current=current.prev;
}
}
}
public class test {

public static void main(String arg[])


{
Node head=new Node('A');
Node temp1=new Node('B');
Node temp2=new Node('C');
Node temp3=new Node('D');
Node tail=new Node('E');
head.prev=null;
head.next=temp1;
temp1.prev=head;
temp1.next=temp2;
temp2.prev=temp1;
temp2.next=temp3;
temp3.prev=temp2;
temp3.next=tail;
tail.prev=temp3;
tail.next=null;
head.displayForward(head);
tail.displayBackword(tail);

You might also like