import java.util.Scanner; class Doublelinked { class Node { int data; Node next; Node back; Node(int d) { data=d; } } Node head=null; Node tail=null; void insertnode(int data) { Node newnode=new Node(data); if(head==null) { head=newnode; tail=newnode; head.back=null; tail.next=null; } else { tail.next=newnode; newnode.back=tail; tail=newnode; tail.next=null; } } public void display() { Node current=head; if(head==null) { System.out.println("No Element"); } else { while(current!=null) { import java.util.Scanner; class Doublelinked { class Node { int data; Node next; Node back; Node(int d) { data=d; } } Node head=null; Node tail=null; void insertnode(int data) { Node newnode=new Node(data); if(head==null) { head=newnode; tail=newnode; head.back=null; tail.next=null; } else { tail.next=newnode; newnode.back=tail; tail=newnode; tail.next=null; } } public void display() { Node current=head; if(head==null) { System.out.println("No Element"); } else { while(current!=null) { System.out.print(""+current.data); current=current.next; } }} public void frontdelet() { try { if(head==null) { System.out.println("No elements to delete"); } head=head.next; if(head==null) { System.out.println("All Elements are deleted"); }} catch(NullPointerException e) { } }} class Main { public static void main (String[]args) { Doublelinked d=new Doublelinked(); int n,i,m,c; Scanner s=new Scanner(System.in); System.out.println("1.Insert node"); System.out.println("2.Display"); System.out.println("3.Deletion from Front"); System.out.println("4 Deletion from back"); while(5<10) { System.out.println("Enter Choice:"); c= s.nextInt(); switch(c) { case 1:System.out.println("Enter No:"); m=s.nextInt(); d.insertnode(m); break; case 2:d.display(); break; case 3:d.frontdelet(); break; default:System.out.println("Invalid key Sorry."); } }}} System.out.print(""+current.data); current=current.next; } }} public void frontdelet() { try { if(head==null) { System.out.println("No elements to delete"); } head=head.next; if(head==null) { System.out.println("All Elements are deleted"); }} catch(NullPointerException e) { } }} class Main { public static void main (String[]args) { Doublelinked d=new Doublelinked(); int n,i,m,c; Scanner s=new Scanner(System.in); System.out.println("1.Insert node"); System.out.println("2.Display"); System.out.println("3.Deletion from Front"); System.out.println("4 Deletion from back"); while(5<10) { System.out.println("Enter Choice:"); c= s.nextInt(); switch(c) { case 1:System.out.println("Enter No:"); m=s.nextInt(); d.insertnode(m); break; case 2:d.display(); break; case 3:d.frontdelet(); break; default:System.out.println("Invalid key Sorry."); } }}}