0% found this document useful (0 votes)
14 views3 pages

Java Double Linked List Operations

This document discusses a double linked list data structure implemented in Java. It defines a Node class with data and next/previous node references. The DLLOperations class implements methods to create a linked list, insert/delete nodes at different positions, display the list forward and backward, and count nodes. A demo class tests the operations by prompting the user for menu choices to add, remove and display nodes in the double linked list.

Uploaded by

Avinash Alla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Java Double Linked List Operations

This document discusses a double linked list data structure implemented in Java. It defines a Node class with data and next/previous node references. The DLLOperations class implements methods to create a linked list, insert/delete nodes at different positions, display the list forward and backward, and count nodes. A demo class tests the operations by prompting the user for menu choices to add, remove and display nodes in the double linked list.

Uploaded by

Avinash Alla
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DOUBLE LINKED LIST

package DLL; [Link]("doyou want to


countinue? y or n");
public class node { choice =[Link]().charAt(0);
node pre; }
int data; while(choice=='y' || choice=='Y');
node next; }
public void display()
public node(int data) {
{ node t=start;
pre=null; while(t!=null)
[Link]=data; {
next=null; [Link]([Link]);
} t=[Link];
} }
}
package DLL; public int count()
{
import [Link]; int c=0;
node t=start;
public class DLLOperations { while(t!=null)
node start=null; {
public void create() c++;
{ t=[Link];
int d; }
Scanner s=new Scanner([Link]); return c;
char choice; }
node latest=null; public int search(int key)
do { {
[Link]("enter data"); node t=start;
d=[Link](); int c=1;
node n =new node(d); while(t!=null)
if(start ==null) {
{ if([Link]==key)
start=n;
latest=n; return c;
} t=[Link];
else c++;
{ }
[Link]=n; return -1;
[Link]=latest;
}
latest=n; public void insertbegin(int d)
} {
DOUBLE LINKED LIST
node n=new node(d); {
[Link]=n; t=[Link];
[Link]=start; [Link]("deleted"+[Link]);
start=n; }
} }
public void insertend(int d) public void deletebetween(int pos)
{ {
node t=start;
node n=new node(d); int c=1;
node t=start; while(c!=pos-1 && [Link]!=null)
while([Link]!=null) {
{ t=[Link];
t=[Link]; c++;
[Link]=n; }
[Link]=t; [Link]([Link]);
} [Link]=t;
} [Link]=[Link];
public void insertbetween(int d,int pos)
{ }
node n=new node(d); public void displayReverse()
node t=start; {
int c=1; node t=start;
while(c!=pos-1 && [Link]!=null) while([Link]!=null)
{ {
t=[Link]; t=[Link];
c++; }
} while(t!=null)
[Link]=[Link]; {
[Link]=t; [Link]([Link]);
[Link]=n; t=[Link];
[Link]=n; }
}
} }
public void deletebegin()
{ package DLL;
[Link]("deleted"+[Link]);
start=[Link]; import [Link];
[Link]=null;
} public class demo {
public void deleteEnd() public static void main(String[]args) {
{ DLLOperations s=new DLLOperations();
node t=start; Scanner sc=new Scanner([Link]);
while([Link]!=null) boolean iterate=true;
DOUBLE LINKED LIST
int choice,d; pos=[Link]();
[Link](); [Link](pos);
while(iterate) break;
{ case 7:
[Link]("menu"); [Link]();
[Link]("[Link] at begin"); break;
[Link]("[Link] at end"); case 8:
[Link]("[Link] in between"); [Link]();
[Link]("[Link] first"); break;
[Link]("[Link] end"); case 9:
[Link]("[Link] between"); [Link]();
[Link]("[Link]"); }
[Link]("[Link] no nodes"); }
[Link]("[Link] reverse");
[Link]("enter choice"); }
choice=[Link]();
switch(choice) }
{
case 1:
[Link]("enter data");
d=[Link]();
[Link](d);
break;
case 2:
[Link]("enter data");
d=[Link]();
[Link](d);
break;
case 3:
[Link]("enter data");
d=[Link]();
[Link]("enter position");
int pos=[Link]();
[Link](d, pos);
break;
case 4:
[Link]();
break;
case 5:
[Link]();
break;
case 6:
[Link]("enter position");

You might also like