2019-03-11 09:59:55 +01:00
|
|
|
(*
|
|
|
|
BSD 2-Clause License
|
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
Copyright (c) 2018, 2019, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE COLLECTIONS;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
TYPE
|
|
|
|
|
|
|
|
ITEM* = POINTER TO RECORD
|
|
|
|
|
|
|
|
link: ITEM
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
COLLECTION* = POINTER TO RECORD
|
|
|
|
|
|
|
|
last: ITEM
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE push* (collection: COLLECTION; item: ITEM);
|
|
|
|
BEGIN
|
|
|
|
item.link := collection.last;
|
|
|
|
collection.last := item
|
|
|
|
END push;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE pop* (collection: COLLECTION): ITEM;
|
|
|
|
VAR
|
|
|
|
item: ITEM;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
item := collection.last;
|
|
|
|
IF item # NIL THEN
|
|
|
|
collection.last := item.link
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN item
|
|
|
|
END pop;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE create* (): COLLECTION;
|
|
|
|
VAR
|
|
|
|
collection: COLLECTION;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
NEW(collection);
|
|
|
|
collection.last := NIL
|
|
|
|
|
|
|
|
RETURN collection
|
|
|
|
END create;
|
|
|
|
|
|
|
|
|
|
|
|
END COLLECTIONS.
|