How Do You Find Out If A Linked-list Has An End? (i.e. The List Is Not A Cycle)

How Do You Find Out If A Linked-list Has An End? (i.e. The List Is Not A Cycle)


  • 19 Dec, 2012

    End of linked list can be found out with the help of "\0" i.e null pointer .

    Comments Received:
    Please give your suggestions and feedback:
  • 16 Mar, 2012

    You can find out by using 2 pointers. One of them goes 2 nodes each time. The second one goes at 1 nodes each time. If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower. If that is the case, then you will know the linked-list is a cycle.

    Comments Received:
    Please give your suggestions and feedback:

2009-2016 downloadmela.com. All rights reserved.