-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubleLinkedList.java
More file actions
52 lines (42 loc) · 923 Bytes
/
DoubleLinkedList.java
File metadata and controls
52 lines (42 loc) · 923 Bytes
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
public class DoubleLinkedList {
private Node head;
private Node tail;
public DoubleLinkedList() {
this.head = null;
this.tail = null;
}
public Node getHead() {
return head;
}
public Node getTail() {
return tail;
}
public void addFirst(int x, int y) {
Node newNode = new Node(x, y);
if (head == null)
head = tail = newNode;
else {
newNode.next = head;
head.prev = newNode;
head = newNode;
}
}
public void delete(Node n) {
int x = n.x;
int y = n.y;
Node actual = head;
while (actual != null) {
if (actual.x == x && actual.y == y) {
if (actual.prev != null)
actual.prev.next = actual.next;
else
head = actual.next;
if (actual.next != null)
actual.next.prev = actual.prev;
else
tail = actual.prev;
}
actual = actual.next;
}
}
}