Skip to content

Instantly share code, notes, and snippets.

@MateusBMP
Created March 16, 2021 22:58
Show Gist options
  • Select an option

  • Save MateusBMP/3c7fa72f5bba8bf6a36b233a3fd8af4d to your computer and use it in GitHub Desktop.

Select an option

Save MateusBMP/3c7fa72f5bba8bf6a36b233a3fd8af4d to your computer and use it in GitHub Desktop.
Lista encadeada simples em Algol 68
# Create structs FAN and QUEUE #
MODE FAN = STRUCT(STRING name, INT ticket),
QUEUE = STRUCT(FAN fan, REF QUEUE next);
# Create NIL queue, default queue and tail and point both to NIL #
REF QUEUE nilq = NIL;
REF REF QUEUE head, tail;
head := tail := LOC REF QUEUE := nilq;
# Add FAN from QUEUE
#
PROC add fan = (REF REF REF QUEUE head, tail,
REF FAN fan)VOID:
tail := next OF (
REF REF QUEUE(head IS nilq|head|tail) :=
HEAP QUEUE :=
(fan, nilq)
);
# Remove FAN from QUEUE
#
PROC remv fan = (REF REF REF QUEUE head)VOID:
head := (head IS nilq|head|next OF head);
# Print complete queue
#
PROC print queue = (REF REF QUEUE head)VOID:
IF head IS nilq
THEN print(("NIL", newline))
ELSE
print((newline, "(", name OF fan OF head, ",", whole(ticket OF fan OF head, 0), ")=>"));
print queue(next OF head)
FI;
print(("? NIL queue:", newline));
print queue(head);
print(newline);
add fan(head, tail, LOC FAN := ("Jim", 1));
add fan(head, tail, LOC FAN := ("Fred", 2));
add fan(head, tail, LOC FAN := ("Eduard", 3));
add fan(head, tail, LOC FAN := ("Iain", 4));
add fan(head, tail, LOC FAN := ("Fiona", 5));
print("? Full queue:");
print queue(head);
print(newline);
remv fan(head);
remv fan(head);
print("? Half queue:");
print queue(head)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment