-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist.rl
88 lines (71 loc) · 1.31 KB
/
linkedlist.rl
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System
class LinkedList
{
var head:Node
def LinkedList :: val:int -> LinkedList
{
Node val -> head
}
def AddLast :: val:int -> void
{
head -> var current:Node
if head == ()
{
Node val -> head
ret ()
}
while current.next != ()
{
current.next -> current
}
Node val -> current.next
}
def AddFirst :: val:int -> void
{
Node val -> var newHead:Node
head -> newHead.next
newHead -> head
}
def Contains :: val:int -> bool
{
head -> var current:Node
while current != ()
{
if current.val == val
{
ret true
}
current.next -> current
}
ret false
}
def Remove :: val:int -> void
{
head -> var current:Node
if head.val == val
{
RemoveHead ()
}
while current.next != ()
{
current.next -> current
}
}
def RemoveHead
{
head.next -> head
}
}
class Node
{
public:
#private:
var next:Node
public:
var val:int
def Node :: value:int -> Node
{
value -> val
() -> next
}
}