forked from bzdgn/data-structures-in-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDCell.java
More file actions
42 lines (32 loc) · 673 Bytes
/
DCell.java
File metadata and controls
42 lines (32 loc) · 673 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
package ds_002_linkedlists;
public class DCell {
public int value;
public DCell prev;
public DCell next;
public DCell(){
value = Integer.MIN_VALUE;
prev = null;
next = null;
}
public DCell(int value) {
this.value = value;
}
public void addAfter(DCell newCell) {
newCell.next = this.next;
newCell.prev = this;
this.next = newCell;
newCell.next.prev = newCell;
}
public void addBefore(DCell newCell) {
// a --- b
// a --- nC --- b
newCell.next = this;
newCell.prev = this.prev;
this.prev.next = newCell;
this.prev = newCell;
}
public void remove() {
this.prev.next = this.next;
this.next.prev = this.prev;
}
}