MCPcopy Create free account
hub / github.com/BeeBombshell/Python-DSA / addAfter

Method addAfter

DSA/circularLinkedList.py:61–88  ·  view source on GitHub ↗
(self, data, item)

Source from the content-addressed store, hash-verified

59 return self.last
60
61 def addAfter(self, data, item):
62
63 # check if the list is empty
64 if self.last == None:
65 return None
66
67 newNode = Node(data)
68 p = self.last.next
69 while p:
70
71 # if the item is found, place newNode after it
72 if p.data == item:
73
74 # make the next of the current node as the next of newNode
75 newNode.next = p.next
76
77 # put newNode to the next of p
78 p.next = newNode
79
80 if p == self.last:
81 self.last = newNode
82 return self.last
83 else:
84 return self.last
85 p = p.next
86 if p == self.last.next:
87 print(item, "The given node is not present in the list")
88 break
89
90 def deleteNode(self, last, key):
91

Callers 1

Calls 1

NodeClass · 0.70

Tested by

no test coverage detected