queue code, based on the stack code.  Sketchy but works.