-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCollections
58 lines (52 loc) · 1 KB
/
Collections
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
LinkedList = λ(){
ll = __Node('__Head__');
return ll;
};
__Node = λ(value){
return [value, null];
};
__IsEmpty = lambda(ll){
return ll[1] == null;
};
RemoveNodeAt = λ(ll, link){
return if (__IsEmpty(ll) == false) then{
return let delve(next = ll[1], i = 0){
if ((i + 1) < link) then{
delve(next[1], (i + 1));
} else {
removed = next[1];
next[1] = removed[1];
return removed[0];
};
};
};
};
GetValAt = λ(ll, link){
return if (__IsEmpty(ll) == false) then{
return let delve(next = ll[1], i = 0){
if (i < link) then{
delve(next[1], (i + 1));
} else {
return next[0];
};
};
};
};
AddToHead = λ(ll, value){
node = __Node(value);
node[1] = ll[1];
ll[1] = node;
return ll;
};
PrintLinkedList = λ(ll){
if (ll[1] != null) then {
let delve(link = ll[1]){
print(link[0]);
if (link[1] != null) then {
print(" -> ");
delve(link[1]);
};
};
println();
};
};