I have a Find function that searches a linked list of strings sequentially. This Find functions finds the string and returns it. I also have a remove function that uses this Find function and removes the string from the linked list. Both of my functions work. However, Im trying to test another way to search the linked list and I am wondering if its possible to do a bisectional search in the linked list. Heres my code:
Find
StringList::StringListNode *StringList::find(const string &s) //basic search function
{
StringListNode *sp = pTop; // Search
while (sp != 0 && sp->data != s)
sp = sp->pNext;
return sp;
}
Here is the remove function:
void StringList::remove(string s)
{
StringListNode *curr = this->find(s);
if (curr->pPrev != 0)
{
curr->pPrev->pNext = curr->pNext;
}
if (curr->pNext != 0)
{
curr->pNext->pPrev = curr->pPrev;
}
if (pTop == curr)
{
pTop = curr->pNext;
}
if (pBottom == curr)
{
pBottom = curr->pPrev;
}
Both my functions work perfectly. Im just wondering if anyone could show me an example on how to search the linked list but instead of a sequential search, i would like to see how a bisectional search would work for learning purposes. Any suggestions? Thanks!