Commits

Nick Wade committed 8770f5f

Simple queue implementation - not threadsafe

  • Participants
  • Parent commits 907a55f

Comments (0)

Files changed (2)

+module CustomQueue : CUSTOMQUEUE = struct
+
+exception Empty = Queue.Empty
+
+type 'a t = 'a Queue.t
+
+let create = Queue.create
+
+let is_empty = Queue.is_empty
+
+let push x q = Queue.push x q
+
+let pop q = if is_empty q then raise Empty else Queue.pop q
+
+let peek q = if is_empty q then raise Empty else Queue.peek q
+
+let clear q = Queue.clear q
+
+let length q = Queue.length q
+
+end
+
+
+
+
+
+module type CUSTOMQUEUE = sig
+
+(** 
+  * A queue contains elements of type 'a - FIFO 
+  * Follows a FIFO style convention
+  *)
+type 'a t
+
+exception Empty
+
+(* Create and return a new empty queue *)
+val create : unit -> 'a t
+
+(* Add e q adds element e to the end of queue q *)
+val push : 'a -> 'a t -> unit
+
+(** Removes and returns the first element in the queue
+  * Raises Empty if the queue is empty 
+  *)
+val pop : 'a t -> 'a
+
+(** Returns the first element in the queue without removing it
+  * Raises Empty if the queue is empty
+  *)
+val peek : 'a t -> 'a
+
+(* Removes all elemenets from the queue *)
+val clear : 'a t -> unit
+
+(* Returns true if the queue is empty, false otherwise *)
+val is_empty : 'a t -> bool
+
+(* Returns the number of elements in the queue *)
+val length : 'a t -> int
+
+end