From 2c6b8c3bf74d2875def9d296e8bac7adcf45ecbe Mon Sep 17 00:00:00 2001 From: enqidu Date: Tue, 7 Jul 2020 13:46:52 +0400 Subject: [PATCH] skip_list --- data_structures/skip_list.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/data_structures/skip_list.cpp b/data_structures/skip_list.cpp index 603d1f2c3..bae1a7bbe 100644 --- a/data_structures/skip_list.cpp +++ b/data_structures/skip_list.cpp @@ -27,7 +27,7 @@ public: /*Forward Array*/ vector forward; Node(int key, int level, void* value); -}; +} Node::Node(int key, int level, void* value) { @@ -37,7 +37,7 @@ Node::Node(int key, int level, void* value) { for (int i = 0; i < sizeof(Node*)*(level+1); i++){ forward.push_back(NULL); } -}; +} // Class for Skip list class SkipList { @@ -50,14 +50,13 @@ public: void deleteElement(int); void* searchElement(int); void displayList(); -}; +} SkipList::SkipList() { level = 0; /* Header initialization*/ header = new Node(-1, MAXLVL, NULL); -}; - +} /** * Returns random level for skip list; @@ -66,7 +65,7 @@ int SkipList::randomLevel() { int lvl = 0; while(rand()%2 < P && lvl < MAXLVL) lvl++; return lvl; -}; +} // Insert given key in skip list @@ -104,8 +103,7 @@ void SkipList::insertElement(int key, void* value) { } else { printf("Exists\n"); } -}; - +} void SkipList::deleteElement(int key) { @@ -134,7 +132,7 @@ void SkipList::deleteElement(int key) } else { printf("Doesnt Exists\n"); } -}; +} /** @@ -156,7 +154,7 @@ void* SkipList::searchElement(int key) { printf("NOT FOUND\n"); return NULL; } -}; +} // Display skip list level wise void SkipList::displayList() { @@ -170,10 +168,9 @@ void SkipList::displayList() { } printf("\n"); } -}; +} -int main() -{ +int main() { srand((unsigned)time(0)); SkipList lst; @@ -184,4 +181,5 @@ int main() } lst.displayList(); + return 0; } \ No newline at end of file