Q related to CLL

Discussion in 'C' started by lakshmikanth, Dec 8, 2006.

  1. lakshmikanth

    lakshmikanth New Member

    Joined:
    Dec 4, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    How can we write a program to know whether a given linked list is circular or not . please reply me with the program
     
  2. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    I won't write the program for you, but if you begin at the head, follow the links, and wind up back at the head, it's circular. If you run off the end of the world and dragons eat you (usually manifested by a NULL pointer), it's not circular. Tip: a simple pencil-and-paper representation of your problems is quite often effective. If you're not into destroying trees, an Etch-A-Sketch will do.
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If you reach the head node while traversing the Linked list then you can safely assume its circular.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice