a*******y 发帖数: 1040 | 1 写code实现struct skip_list * find(struct skip_list *head, int value)
还有这个struct怎么定义? |
l*****a 发帖数: 14598 | 2 这个算法课教吗?
【在 a*******y 的大作中提到】 : 写code实现struct skip_list * find(struct skip_list *head, int value) : 还有这个struct怎么定义?
|
h********6 发帖数: 285 | 3 题目是啥?
【在 a*******y 的大作中提到】 : 写code实现struct skip_list * find(struct skip_list *head, int value) : 还有这个struct怎么定义?
|
w****x 发帖数: 2483 | 4 //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 发帖数: 21240 | 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) : {
|