47
правок
Изменения
м
return lvl
while x.forward[i] != NULL and x.forward[i].value < key x = x.forward[i] x = x.forward[0]
while x.forward[i] != NULL and x.forward[i].value < value x = x.forward[i] update[i] = x
for i = level + 1 to lvl update[i] = header level = lvl
for i = 0 to lvl x.forward[i] = update[i].forward[i] update[i].forward[i] = x
update.assign(MAX_LEVEL + 1, 0)
while x.forward[i] != NULL and x.forward[i].value < value x = x.forward[i] update[i] = x x = x.forward[0]
if update[i].forward[i] != x break update[i].forward[i] = x.forward[i];
level--
Псевдокод отформатирован
int lvl = (int)(log(frand())/log(1.-P))
if lvl < MAX_LEVEL
return MAX_LEVEL
SkipNode x = header
for i = level to 0
return x != NULL && x.value == key
for i = level to 0
x = x.forward[0]
if x == NULL or x.value != value
int lvl = random_level()
if lvl > level
x = new SkipNode(lvl, value)
SkipNode x = header
SkipNode update
for i = level to 0
if x.value == value
for i = 0 to level
delete x
while level > 0 or header.forward[level] == NULL