forked from scala-club/jedit-elastic-tabstops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoublyLinkedList.scala
54 lines (46 loc) · 989 Bytes
/
DoublyLinkedList.scala
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
class Node[T](val t : T) {
private var _parent : Option[Node[T]] = None
private var _child : Option[Node[T]] = None
private def pc = _parent match {
case None => None
case Some(parent) => parent._child
}
private def cp = _child match {
case None => None
case Some(child) => child._parent
}
private def pc_=(c : Option[Node[T]]) {
_parent match {
case None => ()
case Some(parent) => parent._child = c
}
}
private def cp_=(p : Option[Node[T]]) {
_child match {
case None => ()
case Some(child) => child._parent = p
}
}
def remove = {
pc = _child
cp = _parent
_child = None
_parent = None
}
def insertAfter(parent : Node[T]) = {
remove
_child = parent._child
_parent = Some(parent)
parent._child = Some(this)
cp = Some(this)
}
def insertBefore(child : Node[T]) = {
remove
_parent = child._parent
_child = Some(child)
child._parent = Some(this)
pc = Some(this)
}
def parent = _parent
def child = _child
}