Created
April 2, 2017 08:06
-
-
Save sathiyaseelan/43be680bd60d949dfdd70dcca42df8b5 to your computer and use it in GitHub Desktop.
Insert in Sorted Circular Linked List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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