Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,23 @@
component GenericQueue ( Queue, Element );
type Queue;
Queue (MaxLength = integer) -> Queue;
Length( Queue ) -> integer;
Empty ( Queue ) -> boolean;
Full ( Queue ) -> boolean;
Push ( Queue, Element) -> nothing;
Pull ( Queue ) -> Element;
begin
Queue (MaxLength) = Queue:[ MaxLength; length:=0; list=alist(Element) ];
Length ( queue ) = queue.length;
Empty ( queue ) = (queue.length <= 0);
Full ( queue ) = (queue.length >= queue.MaxLength);
Push ( queue, element ) =
[ exception (Full(queue), "Queue Overflow");
queue.length:= queue.length + 1;
add (queue.list, element)];
Pull ( queue ) =
[ exception (Empty(queue), "Queue Underflow");
queue.length:= queue.length - 1;
remove(first(queue.list))];
end component GenericQueue;

View file

@ -0,0 +1,29 @@
use GenericQueue (QueueofPersons, Person);
type Person = text;
Q = QueueofPersons(25);
Push (Q, "Peter");
Push (Q, "Alice");
Push (Q, "Edward");
Q?
QueueofPersons:[MaxLength = 25;
length = 3;
list = { "Peter",
"Alice",
"Edward"}]
Pull (Q)?
"Peter"
Pull (Q)?
"Alice"
Pull (Q)?
"Edward"
Q?
QueueofPersons:[MaxLength = 25;
length = 0;
list = { }]
Pull (Q)?
***** Exception: Queue Underflow