Mutable tail a qnode option there are two parts to a

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if any) *)! val deq : 'a queue -> 'a! end! CIS120 / Spring 2012 4 Datatypes for Mutable Queues type 'a qnode = { ! v: 'a;! mutable next : 'a qnode option! }! type 'a queue = { mutable head : 'a qnode option;! mutable tail : 'a qnode option }! There are two parts to a mutable queue: - the “internal nodes” of the queue with links from one to the next - the head and tail references themselves CIS120 / Spring 2012 5 Example Queues in the Heap Val! head! means Some! Val! tail! An empty queue means head! v! tail! None! next! 1! A queue with one element head! v! tail! next! 1! v! 2! next! A queue with two elements CIS120 / Spring 2012 6 Queue Invariants •  Just as we imposed some [email protected] on which trees are [email protected] Binary Search Trees, Queues must also [email protected] some invariants: Either: (1) head and tail are both None...
View Full Document

This document was uploaded on 11/24/2013.

Ask a homework question - tutors are online