Queue/Definition: Difference between revisions

Content added Content deleted
(add BQN)
Line 1,492: Line 1,492:
Error: queue empty
Error: queue empty
</pre>
</pre>

=={{header|BQN}}==

Queues are already straightforward to make in BQN via its convenient builtins. This object is made for demonstration of BQN's object oriented features. It would generally be much simpler to apply the related functions to an array instead of creating a big object.

<lang bqn>queue ← {
data ← ⟨⟩
Push ⇐ {data∾˜↩𝕩}
Pop ⇐ {
𝕊𝕩:
0=≠data ? •Show "Cannot pop from empty queue";
(data↓˜↩¯1)⊢⊑⌽data
}
Empty ⇐ {𝕊𝕩: 0=≠data}
Display ⇐ {𝕊𝕩: •Show data}
}

q1 ← queue

•Show q1.Empty@
q1.Push 3
q1.Push 4
q1.Display@
•Show q1.Pop@
q1.Display@</lang><lang>1
⟨ 4 3 ⟩
3
⟨ 4 ⟩</lang>


=={{header|Bracmat}}==
=={{header|Bracmat}}==