MCPcopy Index your code
hub / github.com/BeeBombshell/Python-DSA / insert

Method insert

DSA/SinglyLinkedList.py:50–66  ·  view source on GitHub ↗
(self, x, pos)

Source from the content-addressed store, hash-verified

48
49 #method to insert an element at a specific position
50 def insert(self, x, pos):
51 if pos == 1:
52 self.addFront(x)
53 return
54 if pos == (self.count()+1):
55 self.addTail(x)
56 return
57 new_node = Node(x)
58 temp = self.head
59 i = 1
60 while (temp != None) and (i < pos-1):
61 temp = temp.next
62 i += 1
63 if (temp == None):
64 return
65 new_node.next = temp.next
66 temp.next = new_node
67
68 #method to remove the head in the list
69 def removeHead(self):

Callers 2

arrays.pyFile · 0.45

Calls 4

addFrontMethod · 0.95
countMethod · 0.95
addTailMethod · 0.95
NodeClass · 0.70

Tested by

no test coverage detected