Reading material

Pages 78-88.

Additional material

Implementation of a stack by means of an array in Standard ML:
val c = 10; (* capacity of the array *)
val v = 0;  (* value initially stored in the array cells *)

fun empty = (Array.array(c, v), ~1); (* empty stack *)
fun push(x, (a, i)) = ((Array.update(a, i+1, x); a), i+1);
fun pop(a, i) = (a, i-1);
fun top(a, i) = Array.sub(a, i);

Question

Complete the implementation of a queue by means of an array in Standard ML:
val c = 10; (* capacity of the array *)
val v = 0;  (* value initially stored in the array cells *)

val empty = (Array.array(c, v), 0); (* empty queue *)
fun add(x, (a, i)) = ...
local
  fun left(a, j, i) = if (j = i+1) then ... else ...
in
  fun drop(a, i) = (left(a, 1, i), i-1)
end;
fun front(a, i) = ...