问题
How do I perform a binary search on a single linked list headed ? Also it can do it , if there is any particular method. The EP can not tell in advance how many elements of that list , I have to search and enter a cell between q > prox and p .
回答1:
Typically this is not possible, since binary search requires random access, and a singly-linked list can only provide forward sequential access. Without being able to jump around in memory and look at some nth
element (either through direct random-access or a skip list), we end up being required to linearly search through the list from beginning to end even if it's sorted.
来源:https://stackoverflow.com/questions/33929614/binary-search-on-a-single-linked-list