Module Linkedlist (.ml)


module Linkedlist: sig .. end
A doubly linked list implementation.


type 'a node = {
   data : 'a;
   mutable prev : 'a node;
   mutable next : 'a node;
}
Type for doubly linked lists.

type 'a t = {
   mutable l : 'a node option;
   mutable cnt : int;
}
exception Empty_list
Exception thrown when certain operations are attempted on an empty list.
val create_node : 'a -> 'a node
Create a node.
val head_node : 'a t -> 'a node
Get the head node of the given list.
val length : 'a t -> int
Get the size of the given linked list.
val create : 'a -> 'a t
Create a linked list.
val append : 'a -> 'a t -> 'a node
Append to this list.
x : the value to append
l : the list to which to append
val iter : ('a -> 'b) -> 'a t -> unit
Iterate the given linked list.
val create_from_list : 'a list -> 'a t
Create a linked list from a list.
val to_list : 'a t -> 'a list
Convert this linked list into a regular list.
val remove : 'a t -> 'a node -> unit
Delete this item from the list it contains.
val pop_last : 'a t -> 'a
Pop the last item off the list.
val pop_first : 'a t -> 'a
Pop the first item off the list.