-
Notifications
You must be signed in to change notification settings - Fork 3
/
Stak_Queue.oz~
61 lines (60 loc) · 882 Bytes
/
Stak_Queue.oz~
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
declare
class Stack
attr SL
meth init
SL := {NewCell nil}
end
meth size($)
{Length @SL}
end
meth isEmpty($)
@SL==nil
end
meth top($)
case @SL
of H|T then H
else raise emptyStack end
end
end
meth pop($)
case @SL
of H|T then
SL := T
H
else raise emptyStack end
end
end
meth push(X)
SL := X|@SL
end
end
class Queue
attr QL
meth init
QL := {NewCell nil}
end
meth size($)
{Length @QL}
end
meth isEmpty($)
@QL==nil
end
meth front($)
case @SL
of H|T then H
else raise emptyQueue end
end
end
meth dequeue($)
case @QL
of H|T then
QL := T
H
else raise emptyQueue end
end
end
meth enqueue(X)
QL := {Reverse X|{Reverse @SL}}
end
end
{Browse {Reverse [1 2 3 4 5]}}