1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | def insert(self,data,position): if(position==0): newnode=Node(data) newnode.next=self.head self.head=newnode elif(position>self.size): print("\n\nIndex is out of range\n\n") elif(position==self.size): self.append(data) else: current=self.head count=0 while(current!=None): if(count==position-2): break else: count+=1 current=current.next newnode=Node(data) newnode.next=current.next current.next=newnode |