-
Notifications
You must be signed in to change notification settings - Fork 5
/
Experiment18.java
65 lines (65 loc) · 1.88 KB
/
Experiment18.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
/*******************************************************************
* File : Experiment
* Author: Name
* Date : DD/MM/YYYY
*******************************************************************/
import java.util.LinkedList;
import java.util.Scanner;
public class Experiment18 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedList<Integer> list = new LinkedList<Integer>();
int choice;
do {
System.out.println("\n\nDoubly LinkedList Operations\n");
System.out.println(
"1. Add Data to First Position\n2. Add Data to Last Position\n3. Add Data to Particular Position\n4. Delete Data to First Position\n5. Delete Data to Last Position\n6. Delete Data at Particular Position\n7. Display List\n8. Exit");
System.out.print("\nEnter Choice: ");
choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter data: ");
int data = sc.nextInt();
list.addFirst(data);
System.out.print(list);
break;
case 2:
System.out.print("Enter data: ");
int data1 = sc.nextInt();
list.addLast(data1);
System.out.print(list);
break;
case 3:
System.out.print("Enter data: ");
int dat = sc.nextInt();
System.out.print("Enter position: ");
int index = sc.nextInt();
list.add(index-1, dat);
System.out.print(list);
break;
case 4:
list.removeFirst();
System.out.print(list);
break;
case 5:
list.removeLast();
System.out.print(list);
break;
case 6:
System.out.print("Enter position: ");
int index1 = sc.nextInt();
list.remove(index1-1);
System.out.print(list);
break;
case 7:
System.out.print(list);
break;
case 8:
break;
default:
System.out.println("Invalid Option");
}
} while (choice != 8);
sc.close();
}
}