Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
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:

Classes

struct  data_structure::Node
 
class  data_structure::SkipList
 

Namespaces

 data_structure
 Data-structure algorithms.
 

Functions

int main ()
 

Variables

constexpr int data_structure::MAX_LEVEL = 2
 Maximum level of skip list.
 
constexpr float data_structure::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

Function Documentation

◆ main()

int main ( )

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

208  {
209  std::srand(std::time(nullptr));
210 
212 
213  for (int j = 0; j < (1 << (data_structure::MAX_LEVEL + 1)); j++) {
214  int k = (std::rand() % (1 << (data_structure::MAX_LEVEL + 2)) + 1);
215  lst.insertElement(k, &j);
216  }
217 
218  lst.displayList();
219 
220  return 0;
221 }
Here is the call graph for this function:
std::srand
T srand(T... args)
data_structure::SkipList::insertElement
void insertElement(int key, void *value)
Definition: skip_list.cpp:89
data_structure::SkipList::displayList
void displayList()
Definition: skip_list.cpp:187
data_structure::SkipList
Definition: skip_list.cpp:55
std::rand
T rand(T... args)
data_structure::MAX_LEVEL
constexpr int MAX_LEVEL
Maximum level of skip list.
Definition: skip_list.cpp:27
std::time
T time(T... args)