Ad
  • Default User Avatar

    It's impossible to answer your "question" since you don't make it clear what you don't understand - for example, here is the first paragraph from Wikipedia article about linked lists:

    In computer science, a linked list is a linear collection of data elements whose order is not given by their physical placement in memory. Instead, each element points to the next. It is a data structure consisting of a collection of nodes which together represent a sequence. In its most basic form, each node contains: data, and a reference (in other words, a link) to the next node in the sequence.

    Do you understand all of the words/concepts in this small paragraph? If not, then you need to read more.

    If you do understand all the concepts, then let me try to rephrase this kata:

    Referring to the illustration, if you start at node A and only use the node.next attribute, you will visit - in order - B then C then 1 then 2 then 3 .... then 10 then 11 then 12 then 1 aha!! we have reached a node, 1, that we have already visited before. In other words, our linked list contains a loop. The loop is of size 12 since it begins at node #1 and goes all the way to node #12 before returning to node #1.

    Can you figure out a way to "measure" the size of such a loop (in the case, size = 12) in a general linked list, using only the "vist next node" operations (i.e. node.next in this kata) ?