Home My Page Projects Code Snippets Project Openings SML/NJ
 Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

# SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/library/sortedlist.sml
 [smlnj] / sml / trunk / src / MLRISC / library / sortedlist.sml

# Annotation of /sml/trunk/src/MLRISC/library/sortedlist.sml

 1 : monnier 496 (* Copyright 1989 by AT&T Bell Laboratories *) 2 : structure SortedList = 3 : struct 4 : 5 : fun enter(new:int,l) = 6 : let fun f [] = [new] 7 : | f (l as h::t) = if newh then h::f t else l 8 : in f l 9 : end 10 : 11 : fun merge(a,[]) = a 12 : | merge([],a) = a 13 : | merge(l as (i:int)::a, m as j::b) = 14 : if j [] 19 : end 20 : 21 : fun uniq l = 22 : let fun split([],l,r) = (l,r) 23 : | split(h::t,l,r) = split(t,r,h::l) 24 : fun sort [] = [] 25 : | sort (l as [_]) = l 26 : | sort (l as [x : int,y : int]) = 27 : if x = y then [x] else if x < y then l else [y,x] 28 : | sort l = let val (l,r) = split(l,[],[]) 29 : in merge(sort l, sort r) end 30 : in sort l 31 : end 32 : 33 : fun remove(x as (xl:int)::xr, y as yl::yr) = 34 : if xl>yl then yl::remove(x,yr) else remove(xr,if xl