Bounded Stack of E (BST)


datatype BST = 
   New of int  
   | push of BST * int 
   ;

fun empty (New(n)) = true 
  | empty (push(B,e)) = false 
  ;

fun max (New(n)) = n
  | max (push(B,e)) = max(B) 
  ;

fun size (New(n)) = 0
  | size (push(B,e)) = if size(B)=max(B)
                         then max(B)
                         else size(B)+1 
  ;

fun full (New(n)) = false
  | full (push(B,e)) = if size(B)>=max(B)-1
                         then true
                         else false 
  ;

exception topEmptyStack;

fun top (New(n)) = raise topEmptyStack 
  | top (push(B,e)) = if full(B) 
                        then top(B) 
                        else e 
  ;

fun pop (New(n)) = New(n)
  | pop (push(B,e)) = if full(B)
                        then pop(B)
                        else B 
  ;