c++ - Find string using a bisectional search in linked list -
i have find function searches linked list of strings sequentially. find functions finds string , returns it. have remove function uses find function , removes string linked list. both of functions work. however, im trying test way search linked list , wondering if possible bisectional search in linked list. heres 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 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 functions work perfectly. im wondering if show me example on how search linked list instead of sequential search, see how bisectional search work learning purposes. suggestions? thanks!
Comments
Post a Comment