How to find nth element from the end of a singly linked list?

后端 未结 28 1158
感动是毒
感动是毒 2020-12-04 06:08

The following function is trying to find the nth to last element of a singly linked list.

For example:

If the elements are

28条回答
  •  误落风尘
    2020-12-04 06:33

    Since this sounds like homework, I prefer to help you help yourself instead of giving an actual solution.

    I suggest you run this code on some small sample dataset. Use your debugger to run lines step-by-step (you can set a breakpoint at the start of the function). This should give you an idea of how the code works.

    You can also Console.WriteLine() to output variables of interest.

提交回复
热议问题