Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created August 6, 2017 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/d87fcd3f088db5fcb27f20b518ad866c to your computer and use it in GitHub Desktop.
Save kunigami/d87fcd3f088db5fcb27f20b518ad866c to your computer and use it in GitHub Desktop.
let push elem {frontSize; front; rearSize; rear; rotation} =
check {
frontSize;
front;
rearSize = rearSize + 1;
rear = elem :: rear;
rotation;
}
;;
let peek {frontSize; front; rearSize; rear; rotation} = match front with
| [] -> raise Empty_queue
| firstElem :: restFront -> firstElem
;;
let pop {frontSize; front; rearSize; rear; rotation} = match front with
| [] -> raise Empty_queue
| firstElem :: restFront ->
let newState = invalidate rotation in
check {
frontSize = frontSize - 1;
front = restFront;
rearSize;
rear;
rotation = newState;
}
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment