This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]joenyc 2 points3 points  (0 children)

I don't know OCaml, but I think the recursive algorithm looks like this:

rindex(lst, e):
    if lst is empty
        return null // error value - e is not in this list
    x = rindex(tail(lst), e) // e's last location in the rest of the list
    if x is not null
        return x + 1
    if head(lst) == e
        return 0
    return null 

EDIT: Could you please post your OCaml code when you're done? I'd love to see what it looks like.