Linked Lists
8 min · OCaml examples
Chain nodes with next pointers: traverse, count, and update without shifting a whole array.
OCaml · Linked Lists0/5 cleared
Enemy 1 of 5
This builds a chain of three nodes, each pointing to the next, then walks from the first node to the end while counting them. Press Run to see the count printed.
Why this works
OCaml lists are already linked lists: each cell is a head value and a tail list.
Pattern match on Cons (head, tail) or Nil to walk and count nodes.
You
Syntax Skeleton
Loading editor…
Sign up to fightThis one runs on our servers, so it needs a free account.