title: Why I can't create a linked list with a circle?
body: <p>I am trying to create a linkedlist with a infinite circle like this <code>0-&gt;1-&gt;2-&gt;3-&gt;4-&gt;5-**&gt;2**-&gt;3-&gt;4-&gt;5-**&gt;2**-&gt;3-&gt;4-&gt;5-&gt; .........</code>, below is my code:</p>
  <pre><code>class node():
  
      def __init__(self, val):
             self.val = val
             self.nextNode = None
      
      def __repr__(self):
             return &quot;%s&quot; % self.val
      
  class linkedList():
  
      def __init__(self):
             self.head = None
  
      def addNode(self, nodeVal):
             newNode = node(nodeVal)
             if self.head is None:
                 self.head = newNode
             else:
                 tmp = self.head
                 while tmp.nextNode is not None:
                     tmp = tmp.nextNode
                 tmp.nextNode = newNode
      
      def linkNode(self, node):
             if self.head is None:
                 raise Exception(&quot;list can't be None&quot;)
             tmp = self.head
             while tmp.nextNode is not None:
                 tmp = tmp.nextNode
             tmp.nextNode = node
              
      def __repr__(self):           
             tmp = self.head
             val = []
             while tmp is not None:
                 val.append(tmp.val)
                 tmp = tmp.nextNode
             return &quot;vals are %s&quot; % val
  
             
  s = linkedList()
  
  head = node(0)
  node1 = node(1)
  node2 = node(2)
  node3 = node(3)
  node4 = node(4)
  node5 = node(5)
  
  s.addNode(head)
  s.addNode(node1)
  s.addNode(node2)
  s.addNode(node3)
  s.addNode(node4)
  s.addNode(node5)
  s.linkNode(node2)
  
  print(s)
  </code></pre>
  <p>But the output is this: vals are <code>[0, 1, 2, 3, 4, 5, 2]</code> which is not a circle.</p>