-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDoublylinkedlist2.java
68 lines (60 loc) · 1.43 KB
/
Doublylinkedlist2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import java.util.ArrayList;
import java.util.Scanner;
public class Doublylinkedlist2 {
public static void main(String [] args)
{
ArrayList<Integer> List = new ArrayList<>();
try (Scanner sc = new Scanner(System.in)) {
int op;
do
{
System.out.println("\t\tDoubly Linked List");
System.out.println("\t\t------------------\n\n");
System.out.println("1.Add element\n2.Delete element\n3.Exit");
System.out.println("Enter the desired option number : ");
op = sc.nextInt();
switch(op)
{
case 1:
System.out.println("Enter the no of elements to be inserted : ");
int num = sc.nextInt();
System.out.println("Enter the element(s) : ");
for(int i=0;i<num;i++)
{
int element = sc.nextInt();
if(List.add(element))
{
System.out.println("Element added successfully");
}
}
//printing list
System.out.println("The list is : ");
System.out.println(List);
System.out.println("----------------------------------------------");
break;
case 2:
System.out.println("Enter the element to be deleted : ");
int delelement = sc.nextInt();
for( int i =0; i< List.size();i++)
{
if(List.get(i) == delelement)
{
if(List.remove(i) != null)
{
System.out.println("Element deleted successfully");
}
break;
}
}
System.out.println("The list is : ");
System.out.println(List);
System.out.println("----------------------------------------------");
break;
case 3:
System.out.println("Thank you");
break;
}
}while(op!=3);
}
}
}