From: Brian Hurt <bhurt@sp...>  20051004 16:18:17

On Tue, 4 Oct 2005, Amit Dubey wrote: > Looking at Dllist.skip, this looks like a bug. A better implementation of > skip might be: > > let skip node idx = > let rec loop idx n = > if idx == 0 then > n > else if idx>0 then > loop (idx 1) n.next > else > loop (idx + 1) n.prev > in > loop idx node > > (The current version doesn't use n.prev for negative arguments). If there > are no complains, I'll make this change. I'm wondering if it might not be better to split the two loops, to avoid taking repeated branchs: let skip node idx = let rec floop idx n = if idx == 0 then n else floop (idx1) n.next in let rec bloop idx n = if idx == 0 then n else bloop (idx1) n.prev in if idx == 0 then n else if idx > 0 then floop (idx1) n.next else bloop ((idx)1) n.prev ;; Brian 