36 lines
533 B
Plaintext
36 lines
533 B
Plaintext
define :queue [][
|
|
init: [
|
|
this\items: []
|
|
]
|
|
]
|
|
|
|
empty?: function [this :queue][
|
|
zero? this\items
|
|
]
|
|
|
|
push: function [this :queue, item][
|
|
this\items: this\items ++ item
|
|
]
|
|
|
|
pop: function [this :queue][
|
|
ensure -> not? empty? this
|
|
|
|
result: this\items\0
|
|
this\items: remove.index this\items 0
|
|
return result
|
|
]
|
|
|
|
Q: to :queue []
|
|
|
|
push Q 1
|
|
push Q 2
|
|
push Q 3
|
|
|
|
print ["queue is empty?" empty? Q]
|
|
|
|
print ["popping:" pop Q]
|
|
print ["popping:" pop Q]
|
|
print ["popping:" pop Q]
|
|
|
|
print ["queue is empty?" empty? Q]
|