mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
skip_list
This commit is contained in:
parent
910180ff21
commit
8e99383dbf
@ -70,8 +70,7 @@ SkipList::SkipList() {
|
|||||||
*/
|
*/
|
||||||
int SkipList::randomLevel() {
|
int SkipList::randomLevel() {
|
||||||
int lvl = 0;
|
int lvl = 0;
|
||||||
thread_local unsigned int seed = time(NULL);
|
while((float)rand()/RAND_MAX < P && lvl < MAXLVL) lvl++;
|
||||||
while(rand_r(&seed)%2 < P && lvl < MAXLVL) lvl++;
|
|
||||||
return lvl;
|
return lvl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,13 +180,12 @@ void SkipList::displayList() {
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
thread_local unsigned int seed = time(NULL);
|
srand((unsigned)time(0));
|
||||||
|
|
||||||
|
|
||||||
SkipList lst;
|
SkipList lst;
|
||||||
|
|
||||||
for (int j = 0; j < (1 << (MAXLVL+1)); j++){
|
for (int j = 0; j < (1 << (MAXLVL+1)); j++){
|
||||||
int k = (rand_r(&seed) % (1 << (MAXLVL+1) + 1));
|
int k = (rand()% (1 << (MAXLVL+1) + 1));
|
||||||
lst.insertElement(k, &j);
|
lst.insertElement(k, &j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user