SlideShare a Scribd company logo
the header file code for double link list:
#include
#include
#include
#include
#ifndef DOUBLYSKIPLIST_H
#define DOUBLYSKIPLIST_H
using namespace std;
class Node {
public:
int value;
int level;
vector next;
vector prev;
Node(int val, int lvl) : value(val), level(lvl) {
next.resize(lvl + 1, nullptr);
prev.resize(lvl + 1, nullptr);
}
};
class SkipList {
public:
int level;
Node* head;
Node* tail;
int MAXIMUM_ALLOWED_LEVELS;
SkipList(int maxLevels) : MAXIMUM_ALLOWED_LEVELS(maxLevels), level(0) {
head = new Node(INT_MIN, MAXIMUM_ALLOWED_LEVELS);
tail = new Node(INT_MAX, MAXIMUM_ALLOWED_LEVELS);
for (int i = 0; i <= MAXIMUM_ALLOWED_LEVELS; i++) {
head->next[i] = tail;
tail->prev[i] = head;
}
}
int RandomLevel() {
float probability = (float)rand() / RAND_MAX;
int lvl = 0;
while (probability < 0.5 && lvl < MAXIMUM_ALLOWED_LEVELS) {
lvl++;
probability = (float)rand() / RAND_MAX;
}
return lvl;
}
Node* CreateNode(int value, int level) {
return new Node(value, level);
}
void InsertElement(int value) {
Node* current = head;
vector update(MAXIMUM_ALLOWED_LEVELS + 1, nullptr);
for (int i = level; i >= 0; i--) {
while (current->next[i]->value < value) {
current = current->next[i];
}
update[i] = current;
}
current = current->next[0];
if (current->value != value) {
int ranLevel = RandomLevel();
if (ranLevel > level) {
for (int i = level + 1; i <= ranLevel; i++) {
update[i] = head;
}
level = ranLevel;
}
Node* n = CreateNode(value, ranLevel);
for (int i = 0; i <= ranLevel; i++) {
n->next[i] = update[i]->next[i];
n->prev[i] = update[i];
update[i]->next[i]->prev[i] = n;
update[i]->next[i] = n;
}
}
}
void Delete(int value) {
if (!Search(value)) {
cout << value << " does not exist" << endl;
return;
}
Node* current = head;
vector update(MAXIMUM_ALLOWED_LEVELS + 1, nullptr);
for (int i = level; i >= 0; i--) {
while (current->next[i]->value < value) {
current = current->next[i];
}
update[i] = current;
}
current = current->next[0];
for (int i = 0; i <= level; i++) {
if (update[i]->next[i] == current) {
update[i]->next[i] = current->next[i];
current->next[i]->prev[i] = update[i];
}
}
delete current;
}
bool Search(int value) {
Node* current = head;
for (int i = level; i >= 0; i--) {
while (current->next[i]->value < value) {
current = current->next[i];
}
}
current = current->next[0];
return current->value == value;
}
void Show() {
for (int i = 0; i <= level; i++) {
Node* node = head->next[i];
cout << "Level " << i << ": ";
while (node != tail) {
cout << node->value << " -> ";
node = node->next[i];
}
cout << "Tail" << endl;
}
}
void ShowBackwards() {
Node* currTail = tail;
for (int i = 0; i <= level; i++) {
Node* node = currTail->prev[i];
cout << "Level " << i << ": ";
while (node != head) {
cout << node->value << " <- ";
node = node->prev[i];
}
cout << "Head" << endl;
}
}
};
#endif
Code for priority Queue header file below
#ifndef PRIORITYQ_H
#define PRIORITYQ_H
#include
#include
#include // for INT_MAX
#include // for rand()
#include
using namespace std;
class Node {
public:
int data;
int priority; // Priority is also the level in the skip list
std::vector next;
std::vector prev;
Node(int val, int prio) : data(val), priority(prio) {
// Initialize vectors based on priority
next.resize(prio + 1, nullptr);
prev.resize(prio + 1, nullptr);
}
};
class PriorityQueue {
public:
int MAXIMUM_ALLOWED_LEVELS; // Maximum priority/level
Node* head;
Node* tail;
PriorityQueue(int maxLevels) : MAXIMUM_ALLOWED_LEVELS(maxLevels) {
head = new Node(INT_MIN, 0);
tail = new Node(INT_MAX, 0);
head->next.resize(MAXIMUM_ALLOWED_LEVELS + 1, tail);
tail->prev.resize(MAXIMUM_ALLOWED_LEVELS + 1, head);
}
void Enqueue(int data, int priority){
int randomPriority = rand() % (MAXIMUM_ALLOWED_LEVELS + 1);
Node* node = new Node(data, randomPriority);
Node* current = head;
for (int i = MAXIMUM_ALLOWED_LEVELS; i >= 0; i--) {
while (current->next[i]->priority < randomPriority) {
current = current->next[i];
}
}
for (int i = 0; i <= randomPriority; i++) {
node->next[i] = current->next[i];
node->prev[i] = current;
current->next[i]->prev[i] = node;
current->next[i] = node;
}
}
l am trying to complete the task below and my enqueue is not working for some reason, please
help in c++
1. When new item is being enqueued set its data and priority to
random integers (priority is a random integer between 0 and
MAXIMUM_ALLOWED_LEVEL_INDEX which is a property of the
SkipList class)

More Related Content

Similar to the header file code for double link list#include iostream#.pdf

basic programs in C++
basic programs in C++ basic programs in C++
basic programs in C++ Arun Nair
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfaathiauto
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docxBlake0FxCampbelld
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfjyothimuppasani1
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docxacarolyn
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfmail931892
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docxajoy21
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfarjunstores123
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdfharihelectronicspune
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
 
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdfC++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdfarjuncp10
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdffastechsrv
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfanwarsadath111
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docxajoy21
 

Similar to the header file code for double link list#include iostream#.pdf (20)

basic programs in C++
basic programs in C++ basic programs in C++
basic programs in C++
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docximport os import matplotlib-pyplot as plt import pandas as pd import r.docx
import os import matplotlib-pyplot as plt import pandas as pd import r.docx
 
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdfData Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
Data Structure in C++Doubly Linked Lists of ints httpstaffwww.pdf
 
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docxreverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx
reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
In the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdfIn the class we extensively discussed a node class called IntNode in.pdf
In the class we extensively discussed a node class called IntNode in.pdf
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdfC++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
take the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdftake the following code and give details of what each line of code i.pdf
take the following code and give details of what each line of code i.pdf
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdfAnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
AnswerNote LinkedList.cpp is written and driver program main.cpp.pdf
 
#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx#include stdafx.h #include iostream using namespace std;vo.docx
#include stdafx.h #include iostream using namespace std;vo.docx
 

More from fashination

The OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdfThe OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdffashination
 
This is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdfThis is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdffashination
 
There are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdfThere are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdffashination
 
There are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdfThere are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdffashination
 
There are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdfThere are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdffashination
 
The Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdfThe Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdffashination
 
The Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdfThe Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdffashination
 
The provided codetrack_file_handling.rb class Track att.pdf
The provided codetrack_file_handling.rb class Track    att.pdfThe provided codetrack_file_handling.rb class Track    att.pdf
The provided codetrack_file_handling.rb class Track att.pdffashination
 
The following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdfThe following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdffashination
 
The financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdfThe financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdffashination
 
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdfThe plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdffashination
 

More from fashination (11)

The OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdfThe OSI reference model Select all of the following statements that.pdf
The OSI reference model Select all of the following statements that.pdf
 
This is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdfThis is business law but it is not an available option for subjects..pdf
This is business law but it is not an available option for subjects..pdf
 
There are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdfThere are two views regarding the social responsibility of business.pdf
There are two views regarding the social responsibility of business.pdf
 
There are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdfThere are several different methods of data gathering in research. Her.pdf
There are several different methods of data gathering in research. Her.pdf
 
There are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdfThere are several different methods of data gathering in research. H.pdf
There are several different methods of data gathering in research. H.pdf
 
The Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdfThe Windows CreateProcess() system call creates a new process. What .pdf
The Windows CreateProcess() system call creates a new process. What .pdf
 
The Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdfThe Seven Major Sources of Economic Progress are a framework that .pdf
The Seven Major Sources of Economic Progress are a framework that .pdf
 
The provided codetrack_file_handling.rb class Track att.pdf
The provided codetrack_file_handling.rb class Track    att.pdfThe provided codetrack_file_handling.rb class Track    att.pdf
The provided codetrack_file_handling.rb class Track att.pdf
 
The following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdfThe following MATLAB code generates the plot of the unit-sample resp.pdf
The following MATLAB code generates the plot of the unit-sample resp.pdf
 
The financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdfThe financial statements and industry norms are shown below for Ever.pdf
The financial statements and industry norms are shown below for Ever.pdf
 
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdfThe plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
The plaintiff, Smith, is a United States Marine Corps veteran. He su.pdf
 

Recently uploaded

Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativePeter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxJisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfYibeltalNibretu
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxJisc
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chipsGeoBlogs
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxbennyroshan06
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxakshayaramakrishnan21
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfkaushalkr1407
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersPedroFerreira53928
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptSourabh Kumar
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxricssacare
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfTamralipta Mahavidyalaya
 

Recently uploaded (20)

Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 

the header file code for double link list#include iostream#.pdf

  • 1. the header file code for double link list: #include #include #include #include #ifndef DOUBLYSKIPLIST_H #define DOUBLYSKIPLIST_H using namespace std; class Node { public: int value; int level; vector next; vector prev; Node(int val, int lvl) : value(val), level(lvl) { next.resize(lvl + 1, nullptr); prev.resize(lvl + 1, nullptr); } }; class SkipList { public: int level; Node* head; Node* tail; int MAXIMUM_ALLOWED_LEVELS;
  • 2. SkipList(int maxLevels) : MAXIMUM_ALLOWED_LEVELS(maxLevels), level(0) { head = new Node(INT_MIN, MAXIMUM_ALLOWED_LEVELS); tail = new Node(INT_MAX, MAXIMUM_ALLOWED_LEVELS); for (int i = 0; i <= MAXIMUM_ALLOWED_LEVELS; i++) { head->next[i] = tail; tail->prev[i] = head; } } int RandomLevel() { float probability = (float)rand() / RAND_MAX; int lvl = 0; while (probability < 0.5 && lvl < MAXIMUM_ALLOWED_LEVELS) { lvl++; probability = (float)rand() / RAND_MAX; } return lvl; } Node* CreateNode(int value, int level) { return new Node(value, level); } void InsertElement(int value) { Node* current = head; vector update(MAXIMUM_ALLOWED_LEVELS + 1, nullptr); for (int i = level; i >= 0; i--) { while (current->next[i]->value < value) {
  • 3. current = current->next[i]; } update[i] = current; } current = current->next[0]; if (current->value != value) { int ranLevel = RandomLevel(); if (ranLevel > level) { for (int i = level + 1; i <= ranLevel; i++) { update[i] = head; } level = ranLevel; } Node* n = CreateNode(value, ranLevel); for (int i = 0; i <= ranLevel; i++) { n->next[i] = update[i]->next[i]; n->prev[i] = update[i]; update[i]->next[i]->prev[i] = n; update[i]->next[i] = n; } } } void Delete(int value) { if (!Search(value)) { cout << value << " does not exist" << endl; return; } Node* current = head; vector update(MAXIMUM_ALLOWED_LEVELS + 1, nullptr);
  • 4. for (int i = level; i >= 0; i--) { while (current->next[i]->value < value) { current = current->next[i]; } update[i] = current; } current = current->next[0]; for (int i = 0; i <= level; i++) { if (update[i]->next[i] == current) { update[i]->next[i] = current->next[i]; current->next[i]->prev[i] = update[i]; } } delete current; } bool Search(int value) { Node* current = head; for (int i = level; i >= 0; i--) { while (current->next[i]->value < value) { current = current->next[i]; } } current = current->next[0];
  • 5. return current->value == value; } void Show() { for (int i = 0; i <= level; i++) { Node* node = head->next[i]; cout << "Level " << i << ": "; while (node != tail) { cout << node->value << " -> "; node = node->next[i]; } cout << "Tail" << endl; } } void ShowBackwards() { Node* currTail = tail; for (int i = 0; i <= level; i++) { Node* node = currTail->prev[i]; cout << "Level " << i << ": "; while (node != head) { cout << node->value << " <- "; node = node->prev[i]; } cout << "Head" << endl; } } }; #endif Code for priority Queue header file below #ifndef PRIORITYQ_H
  • 6. #define PRIORITYQ_H #include #include #include // for INT_MAX #include // for rand() #include using namespace std; class Node { public: int data; int priority; // Priority is also the level in the skip list std::vector next; std::vector prev; Node(int val, int prio) : data(val), priority(prio) { // Initialize vectors based on priority next.resize(prio + 1, nullptr); prev.resize(prio + 1, nullptr); } }; class PriorityQueue { public: int MAXIMUM_ALLOWED_LEVELS; // Maximum priority/level Node* head; Node* tail; PriorityQueue(int maxLevels) : MAXIMUM_ALLOWED_LEVELS(maxLevels) { head = new Node(INT_MIN, 0); tail = new Node(INT_MAX, 0); head->next.resize(MAXIMUM_ALLOWED_LEVELS + 1, tail);
  • 7. tail->prev.resize(MAXIMUM_ALLOWED_LEVELS + 1, head); } void Enqueue(int data, int priority){ int randomPriority = rand() % (MAXIMUM_ALLOWED_LEVELS + 1); Node* node = new Node(data, randomPriority); Node* current = head; for (int i = MAXIMUM_ALLOWED_LEVELS; i >= 0; i--) { while (current->next[i]->priority < randomPriority) { current = current->next[i]; } } for (int i = 0; i <= randomPriority; i++) { node->next[i] = current->next[i]; node->prev[i] = current; current->next[i]->prev[i] = node; current->next[i] = node; } } l am trying to complete the task below and my enqueue is not working for some reason, please help in c++ 1. When new item is being enqueued set its data and priority to random integers (priority is a random integer between 0 and MAXIMUM_ALLOWED_LEVEL_INDEX which is a property of the SkipList class)