Sorted insert for circular linked list

def insert(self,new_data):
temp = self.head
new_node = Node(new_data)
if temp == None:
self.head = new_node
new_node.next = self.head

return
while(temp):
if temp.next == self.head:
temp.next = new_node
new_node.next = self.head
return
if temp.data < new_data:
prev = temp
temp = temp.next
if temp.data>new_data:
prev.next = new_node
new_node.next = temp
return

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sairam Penjarla

Sairam Penjarla

Looking for my next opportunity to make change in a BIG way