Implementation of the enqueue/dequeue operation for new gray queue encoding.