46 lines
823 B
Plaintext
46 lines
823 B
Plaintext
define :item [priority, value][
|
|
print: [
|
|
~"(|this\priority|, |this\value|)"
|
|
]
|
|
]
|
|
define :queue [items][
|
|
init: [
|
|
this\items: arrange this\items 'it -> it\priority
|
|
]
|
|
]
|
|
|
|
empty?: function [this :queue][
|
|
zero? this\items
|
|
]
|
|
|
|
push: function [this :queue, item][
|
|
this\items: this\items ++ item
|
|
this\items: arrange this\items 'it -> it\priority
|
|
]
|
|
|
|
pop: function [this :queue][
|
|
ensure -> not? empty? this
|
|
|
|
result: this\items\0
|
|
this\items: remove.index this\items 0
|
|
return result
|
|
]
|
|
|
|
Q: to :queue @[to [:item] [
|
|
[3 "Clear drains"]
|
|
[4 "Feed cat"]
|
|
[5 "Make tea"]
|
|
[1 "Solve RC tasks"]
|
|
]]
|
|
|
|
push Q to :item [2 "Tax return"]
|
|
|
|
print ["queue is empty?" empty? Q]
|
|
print ""
|
|
|
|
while [not? empty? Q]->
|
|
print ["task:" pop Q]
|
|
|
|
print ""
|
|
print ["queue is empty?" empty? Q]
|