datatype StompStack =
New of int
| con of StompStack * int
;
fun empty (New(n)) = true
| empty (con(S,i)) = false
;
fun max (New(n)) = n
| max (con(S,i)) = max(S)
;
fun size (New(n)) = 0
| size (con(B,i)) = if size(B)=max(B)
then max(B)
else size(B)+1
;
fun full (New(m)) = m=0
| full (con(S,i)) = if size(S)>=max(S)-1
then true
else false
;
exception topEmptyStack;
fun top (New(n)) = raise topEmptyStack
| top (con(S,i)) = if full(S)
then top(S)
else i
;
fun pop (New(n)) = New(n)
| pop (con(S,i)) = if full(S)
then pop(S)
else S
;
fun rem (New(n)) = New(n)
| rem (con(New(n),i)) = New(n)
| rem (con(S,i))= con(rem(S),i);
fun push (New(n),i)= con(New(n),i)|
push (S,i)= if full(S)
then con(rem(S),i)
else con(S,i);
val ns5 = New(5);
val s1 = push (ns5,1);
val s2 = push (s1,2);
val s3 = push (s2,3);
val s4 = push (s3, 4);
val s5 = push (s4, 4);
val s6 = push (s5, 5);
val s7 = push (s6, 6);
New of int
| con of StompStack * int
;
fun empty (New(n)) = true
| empty (con(S,i)) = false
;
fun max (New(n)) = n
| max (con(S,i)) = max(S)
;
fun size (New(n)) = 0
| size (con(B,i)) = if size(B)=max(B)
then max(B)
else size(B)+1
;
fun full (New(m)) = m=0
| full (con(S,i)) = if size(S)>=max(S)-1
then true
else false
;
exception topEmptyStack;
fun top (New(n)) = raise topEmptyStack
| top (con(S,i)) = if full(S)
then top(S)
else i
;
fun pop (New(n)) = New(n)
| pop (con(S,i)) = if full(S)
then pop(S)
else S
;
fun rem (New(n)) = New(n)
| rem (con(New(n),i)) = New(n)
| rem (con(S,i))= con(rem(S),i);
fun push (New(n),i)= con(New(n),i)|
push (S,i)= if full(S)
then con(rem(S),i)
else con(S,i);
val ns5 = New(5);
val s1 = push (ns5,1);
val s2 = push (s1,2);
val s3 = push (s2,3);
val s4 = push (s3, 4);
val s5 = push (s4, 4);
val s6 = push (s5, 5);
val s7 = push (s6, 6);