Skip to content

Conversation

@ErdemT09
Copy link
Collaborator

@ErdemT09 ErdemT09 commented Jul 3, 2021

Resolves: #88

Algorithm:

Here, it's best to think about what might occur when we are inserting the value into such a list:
It could be inserted between values. 5 will naturally be inserted after 4 and before 6.
It could be inserted at the end of the list. At the end of the list, the next value is smaller than the previous one. A node would be inserted here if and only if succeeds the largest value or precedes the smallest value.
The algorithm follows from these simple observations.

Copy link
Collaborator

@altay9 altay9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice explanation, easy-to-understand solution, and readable code. Thanks, Erdem.

@ErdemT09 ErdemT09 merged commit 40da6c5 into master Jul 4, 2021
@ErdemT09 ErdemT09 deleted the 708.-Insert-into-a-Sorted-Circular-Linked-List branch July 4, 2021 04:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

708. Insert into a Sorted Circular Linked List

3 participants