Public class DLL{ public DLLNode first; public DLLNode last; public DLL() {this.first=Null; this.last=Null;} Public void Display() {if (first==Null) {s.o.p(“ the list is empty”);} else {for (DLLNode curr=first; curr!=Null; curr=curr.succ) {System.out.println(“the element is”+ curr.element); }} Public void AddBegining(DLLNode Node) {Node.succ=first; First.prev=Node First=Node; Node.prev=Null; if(first ==null && last==null) Last=node; } Public void Append(DLLNode Node) {Node.succ=Null; if(first==Null) {first=Node; Node.prev=Null} Public void insetAfter(int obj, DLLNode Node) {DLLNode curr=first; while((curr!=Null)&&( curr.element!=obj)) { curr=curr.succ; } If(curr.element==obj) {Node.succ=curr.succ; Curr.succ.prev=Node; Curr.succ=Node; Node.prev=curr;} Else System.out.println(“the element doesn’t exist”); Public void delete(DLLNode del) { if(first==Null) {System.out.println(“the list is empty”); } Else if(del==first) {first==del.succ;} Else if(del.succ==Null) first=Null; last=Null; Else {DLLNode ptr= first; while(ptr.succ!=del) {Ptr=ptr.succ;} Public class DLLNode{ int element; DLLNode prev; DLLNode succ; Public DLLNode(int E) {this. Element=E; This. prev=Null; This.succ=Null} Public static void main(String args[]) {DLL list = new DLL(); Scanner s = new Scanner(System.in); Int X,Y,Size; DLLNode Node1= new DLLNode(5); DLLNode Node2= new DLLNode(6); DLLNode Node3= new DLLNode(7); DLLNode Node4= new DLLNode(9); list.AddBegining(Node1); list.Append(Node2); list.Append(Node3); list.Append(Node4); list.Display(); 1. Count the number of nodes 2. Insert a new node before the value 7 of Double Linked List 3. Search an existing element in a Double linked list (the element of search is given by the user) Suppose List contained the following Test Data: Input the number of nodes : 4 Input data for node 1 : 5 Input data for node 2 : 6 Input data for node 3 : 7 Input data for node 4: 9
Public class DLL{
public DLLNode first;
public DLLNode last;
public DLL()
{this.first=Null;
this.last=Null;}
Public void Display()
{if (first==Null)
{s.o.p(“ the list is empty”);}
else
{for (DLLNode curr=first; curr!=Null; curr=curr.succ)
{System.out.println(“the element is”+ curr.element);
}}
Public void AddBegining(DLLNode Node)
{Node.succ=first;
First.prev=Node
First=Node;
Node.prev=Null;
if(first ==null && last==null)
Last=node;
}
Public void Append(DLLNode Node)
{Node.succ=Null;
if(first==Null)
{first=Node;
Node.prev=Null}
Public void insetAfter(int obj, DLLNode Node)
{DLLNode curr=first;
while((curr!=Null)&&( curr.element!=obj))
{ curr=curr.succ; }
If(curr.element==obj)
{Node.succ=curr.succ;
Curr.succ.prev=Node;
Curr.succ=Node;
Node.prev=curr;}
Else
System.out.println(“the element doesn’t exist”);
Public void delete(DLLNode del)
{
if(first==Null)
{System.out.println(“the list is empty”); }
Else if(del==first)
{first==del.succ;}
Else if(del.succ==Null)
first=Null;
last=Null;
Else
{DLLNode ptr= first;
while(ptr.succ!=del)
{Ptr=ptr.succ;}
Public class DLLNode{
int element;
DLLNode prev;
DLLNode succ;
Public DLLNode(int E)
{this. Element=E;
This. prev=Null;
This.succ=Null}
Public static void main(String args[])
{DLL list = new DLL();
Scanner s = new Scanner(System.in);
Int X,Y,Size;
DLLNode Node1= new DLLNode(5);
DLLNode Node2= new DLLNode(6);
DLLNode Node3= new DLLNode(7);
DLLNode Node4= new DLLNode(9);
list.AddBegining(Node1);
list.Append(Node2);
list.Append(Node3);
list.Append(Node4);
list.Display();
1. Count the number of nodes
2. Insert a new node before the value 7 of Double Linked List
3. Search an existing element in a Double linked list (the element of search
is given by the user)
Suppose List contained the following Test Data: Input the number of nodes : 4
Input data for node 1 : 5
Input data for node 2 : 6
Input data for node 3 : 7 Input data for node 4: 9
Step by step
Solved in 4 steps with 5 images