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);