mou*_*919 1 ocaml position element list
在OCaml中获取元素列表中元素位置的最快方法是什么?我知道如何在列表中获取元素的"第n"位置,但我想知道如果我已经知道该值,如何获取该元素的位置.
Jac*_*ale 9
我相信最快的方式是最常用的方式:
时间复杂度为O(N)
let index_of e l = let rec index_rec i = function | [] -> raise Not_found | hd::tl -> if hd = e then i else index_rec (i+1) tl in index_rec 0 l
归档时间:
12 年,3 月 前
查看次数:
1439 次
最近记录: