diff options
-rw-r--r-- | src/vylist.ml | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/vylist.ml b/src/vylist.ml index c6a1044..9afea5f 100644 --- a/src/vylist.ml +++ b/src/vylist.ml @@ -15,3 +15,15 @@ let rec replace p x xs = | [] -> [] | x' :: xs' -> if (p x') then x :: xs' else x' :: (replace p x xs') + +let rec insert_before p x xs = + match xs with + | [] -> raise Not_found + | y :: ys -> if (p y) then x :: y :: ys + else y :: (insert_before p x ys) + +let rec insert_after p x xs = + match xs with + | [] -> raise Not_found + | y :: ys -> if (p y) then y :: x :: ys + else y :: (insert_after p x ys) |