-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkedList.java
54 lines (46 loc) · 1.44 KB
/
LinkedList.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
package DSL_MiniProject;
class LinkedList {
NodeinLL head;
public void insert(Passenger passenger) {
NodeinLL newNode = new NodeinLL(passenger);
newNode.next = head;
head = newNode;
}
public Passenger search(String email) {
NodeinLL current = head;
while (current != null) {
if (current.passenger.getEmail().equals(email)) {
return current.passenger;
}
current = current.next;
}
return null; // Passenger NOT found
}
/*public void updateEmail(String currentEmail, String newEmail) {
NodeinLL current = head;
while (current != null) {
if (current.passenger.getEmail().equals(currentEmail)) {
current.passenger.setEmail(newEmail);
return;
}
current = current.next;
}
}*/
public void deleteEmail(String email) {
if (head == null) {
return; // List is empty
}
if (head.passenger.getEmail().equals(email)) {
head = head.next;
return;
}
NodeinLL current = head;
while (current.next != null) {
if (current.next.passenger.getEmail().equals(email)) {
current.next = current.next.next;
return;
}
current = current.next;
}
}
}