title: Unable to Insert node in Circular Singly linked list
body: <p>I'm not able to get the desired output in the given code. The code is about <strong>inserting nodes</strong> in the <strong>circular singly linked list</strong>. Please correct this code as per the problems stated.</p>
  <pre><code>class Node:
      def __init__(self,value):
          self.value = value
          self.next = None
   
  class CircularSLL:
      
      def __init__(self):
          self.head = None
          self.tail = None
          
      def __iter__(self):
          node = self.head
          while node:
              yield node
              if node.next == self.head:
                  print('break')
                  break
              node = node.next
              
      def insertnode(self, value, location):
          new_node = Node(value)
          
          # check if head is None or not
          
          if self.head is None:
              self.head = new_node
              self.tail = new_node
              new_node.next = self.head
              
          else:
              
              
              
              # At the start
              if location == 0:
                  new_node.next = self.head
                  self.head = new_node
                  self.tail.next = self.head
              
              # At the end
              elif location == -1:
                  new_node.next = self.tail.next
                  self.tail.next = new_node
                  self.tail = new_node
                  
              else:
                  
                  # At specific location
                  temp_node = self.head
                  index = 0
                  
                  while index &lt; location - 1:
                      
                      # node is the last element
                      if temp_node.next == self.head:
                          break
                      temp_node = temp_node.next
                      index += 1
                  
                  next_node = temp_node.next
                  temp_node.next = new_node
                  new_node.next = next_node
                  
                  if temp_node.next == self.head:
                      self.tail == temp_node
                      self.tail.next = self.head
                  
              return 'The node has been successfully inserted'
   
  cll = CircularSLL()
   
  cll.insertnode(1,0)
   
  cll.insertnode(3, 1)
   
  cll.insertnode(4, 2)
   
  cll.insertnode(5, 3)
   
  cll.insertnode(6, 4)
   
  print([node.value for node in call]) 
  </code></pre>
  <p>output = [1,3,4,5,6 ]</p>
  <p><strong>1st problem - when inserting at index =  '0'.</strong></p>
  <pre><code>cll.insertnode(10,0)
  </code></pre>
  <p>output = [10,1]</p>
  <p><strong>expected</strong></p>
  <p>output = [10,1,3,4,5,6]</p>
  <p><strong>2nd problem - when putting location = '-1'</strong></p>
  <pre><code>cll.insertnode(30, -1)
  </code></pre>
  <p>output = [1, 30]</p>
  <p><strong>expected</strong></p>
  <p>output = [10,1,3,4,5,6,30]</p>