Subversion Repositories Kolibri OS

Rev

Rev 7693 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. (*
  2.     BSD 2-Clause License
  3.  
  4.     Copyright (c) 2018, Anton Krotov
  5.     All rights reserved.
  6. *)
  7.  
  8. MODULE COLLECTIONS;
  9.                  
  10.  
  11. TYPE
  12.  
  13.     ITEM* = POINTER TO RECORD
  14.  
  15.         link: ITEM
  16.  
  17.     END;
  18.  
  19.     COLLECTION* = POINTER TO RECORD
  20.  
  21.         last: ITEM
  22.  
  23.     END;
  24.  
  25.  
  26. PROCEDURE push* (collection: COLLECTION; item: ITEM);
  27. BEGIN
  28.     item.link := collection.last;
  29.     collection.last := item
  30. END push;
  31.  
  32.  
  33. PROCEDURE pop* (collection: COLLECTION): ITEM;
  34. VAR
  35.     item: ITEM;
  36.  
  37. BEGIN
  38.     item := collection.last;
  39.     IF item # NIL THEN
  40.         collection.last := item.link
  41.     END
  42.  
  43.     RETURN item
  44. END pop;
  45.  
  46.  
  47. PROCEDURE create* (): COLLECTION;
  48. VAR
  49.     collection: COLLECTION;
  50.  
  51. BEGIN
  52.     NEW(collection);
  53.     collection.last := NIL
  54.  
  55.     RETURN collection
  56. END create;
  57.  
  58.  
  59. END COLLECTIONS.