MCPcopy
hub / github.com/geekcomputers/Python / insert

Method insert

singly_linked_list.py:36–56  ·  view source on GitHub ↗
(self, pos, data)

Source from the content-addressed store, hash-verified

34 del temp
35
36 def insert(self, pos, data):
37 if pos < 0 or pos > self.length():
38 print("Enter valid index")
39 elif pos == 0:
40 self.insert_at_head(data)
41 return
42 elif pos == self.length() - 1:
43 self.add_node(data)
44 return
45 new_node = Node(data)
46 curr_pos = 0
47 prev = None
48 curr = self.head
49 while True:
50 if pos == curr_pos:
51 prev.next = new_node
52 new_node.next = curr
53 break
54 prev = curr
55 curr = curr.next
56 curr_pos += 1
57
58 def delete_head(self):
59 temp = self.head

Callers 15

calc1Function · 0.45
calc2Function · 0.45
calc3Function · 0.45
calc4Function · 0.45
calc5Function · 0.45
calc6Function · 0.45
calc7Function · 0.45
calc8Function · 0.45
calc9Function · 0.45
calc0Function · 0.45
equalsFunction · 0.45
add_ButtonFunction · 0.45

Calls 4

lengthMethod · 0.95
insert_at_headMethod · 0.95
add_nodeMethod · 0.95
NodeClass · 0.70

Tested by 11

get_char_listMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36
generateMethod · 0.36