Skip to content

Instantly share code, notes, and snippets.

@sathiyaseelan
Created April 2, 2017 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathiyaseelan/43be680bd60d949dfdd70dcca42df8b5 to your computer and use it in GitHub Desktop.
Save sathiyaseelan/43be680bd60d949dfdd70dcca42df8b5 to your computer and use it in GitHub Desktop.
Insert in Sorted Circular Linked List
def insert(new_node)
if tail == nil
new_node.next = new_node
tail = new_node
else
curr = tail.next
while curr.next != tail && curr.data <= new_node.data
curr = curr.next
end
new_node.next = curr.next
curr.next = new_node
if curr == tail && curr.data >= tail.data
tail = new_node
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment