TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
skip_list.cpp File Reference

Data structure for fast searching and insertion in \(O(\log n)\) time. More...

#include <array>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <vector>
Include dependency graph for skip_list.cpp:

Go to the source code of this file.

Classes

struct  data_structures::Node
 
class  data_structures::SkipList
 

Namespaces

namespace  data_structures
 for IO operations
 

Functions

int main ()
 

Variables

constexpr int data_structures::MAX_LEVEL = 2
 Maximum level of skip list.
 
constexpr float data_structures::PROBABILITY = 0.5
 Current probability for "coin toss".
 

Detailed Description

Data structure for fast searching and insertion in \(O(\log n)\) time.

A skip list is a data structure that is used for storing a sorted list of items with a help of hierarchy of linked lists that connect increasingly sparse subsequences of the items

References used: GeeksForGeek, OpenGenus for PseudoCode and Code

Author
enqidu
Krishna Vedala

Definition in file skip_list.cpp.

Function Documentation

◆ main()

int main ( void )

Main function: Creates and inserts random 2^[number of levels] elements into the skip lists and than displays it

Definition at line 212 of file skip_list.cpp.

212 {
213 std::srand(std::time(nullptr));
214
216
217 for (int j = 0; j < (1 << (data_structures::MAX_LEVEL + 1)); j++) {
218 int k = (std::rand() % (1 << (data_structures::MAX_LEVEL + 2)) + 1);
219 lst.insertElement(k, &j);
220 }
221
222 lst.displayList();
223
224 return 0;
225}
void insertElement(int key, void *value)
Definition skip_list.cpp:90
double k(double x)
Another test function.
constexpr int MAX_LEVEL
Maximum level of skip list.
Definition skip_list.cpp:27