Re: Slice sequence--new algorithm
Lutz, Al & co,
I think the routines below for removal of all occurrences of an
element from a sequence are both simpler and slightly faster than the
ones proposed so far.
jiri
function remove(sequence s, integer n)
integer p
p = 0
for i = 1 to length(s) do
if s[i] != n then
p += 1
s[p] = s[i]
end if
end for
return s[1..p]
end function
-- generalized:
function remove(sequence s, object n)
integer p
p = 0
for i = 1 to length(s) do
if compare(s[i], n) then
p += 1
s[p] = s[i]
end if
end for
return s[1..p]
end function
|
Not Categorized, Please Help
|
|