//How to find a value in a skip list //about skip-list http://en.wikipedia.org/wiki/File:Skip_list.svg struct SKIP_NODE { int nVal; vector links; }; //sort like binary search, scope down to decrease the searching range SKIP_NODE* Find(SKIP_NODE* pHead, int x) { assert(pHead); SKIP_NODE* pCur = pHead; int nIndex = pHead->links.size() - 1; while (nIndex >= 0) { if (pCur->nVal == x) return pCur; if (pCur->links[nIndex] == NULL || pCur->links[nIndex]->nVal > x) nIndex--; else pCur = pCur->links[nIndex]; } return NULL; }
p*2
5 楼
牛x,这个有时间得学习一下。上次有人提到跳表我一点也不懂。
【在 w****x 的大作中提到】 : //How to find a value in a skip list : //about skip-list http://en.wikipedia.org/wiki/File:Skip_list.svg : struct SKIP_NODE : { : int nVal; : vector links; : }; : //sort like binary search, scope down to decrease the searching range : SKIP_NODE* Find(SKIP_NODE* pHead, int x) : {