We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
If input is given to you in sorted order, then you would only have to insert each element at the end of the list. That wouldn't test your ability to insert items into a sorted list.
An empty list is sorted with respect to itself, as is a one-element list. You must insert one element into this list during each call to the function. The data value given during each call is not ordered because, again, giving you ordered data would only test your ability to insert an element at the tail of a list. Your code must ensure that the insertion point for each element you add to the list doesn't cause the list to become unsorted.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
If input is given to you in sorted order, then you would only have to insert each element at the end of the list. That wouldn't test your ability to insert items into a sorted list.
An empty list is sorted with respect to itself, as is a one-element list. You must insert one element into this list during each call to the function. The data value given during each call is not ordered because, again, giving you ordered data would only test your ability to insert an element at the tail of a list. Your code must ensure that the insertion point for each element you add to the list doesn't cause the list to become unsorted.