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_structures::Node
class | data_structures::SkipList

## Namespaces

| data_structures
| Data Structures algorithms.

## 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

## 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

{
std::srand(std::time(nullptr));
data_structures::SkipList lst;
for (int j = 0; j < (1 << (data_structures::MAX_LEVEL + 1)); j++) {
int k = (std::rand() % (1 << (data_structures::MAX_LEVEL + 2)) + 1);
lst.insertElement(k, &j);
}
lst.displayList();
return 0;
}
data_structures::SkipList
Definition: skip_list.cpp:55
data_structures::SkipList::insertElement
void insertElement(int key, void *value)
Definition: skip_list.cpp:90
data_structures::SkipList::displayList
void displayList()
Definition: skip_list.cpp:191
data_structures::MAX_LEVEL
constexpr int MAX_LEVEL
Maximum level of skip list.
Definition: skip_list.cpp:27
std::rand
T rand(T... args)
std::srand
T srand(T... args)
std::time
T time(T... args)
Here is the call graph for this function: