SlideShare a Scribd company logo
Double linked list header file below for FYI
#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
PriorityQueue header file code 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);
}
~PriorityQueue() {
Node* current = head;
while (current) {
Node* nextNode = current->next[0];
delete current;
current = nextNode;
}
}
void Enqueue(int data, int priority) {
Node* node = new Node(data, priority);
Node* current = head;
for (int i = MAXIMUM_ALLOWED_LEVELS; i >= 0; i--) {
while (current->next[i]->priority < priority) {
current = current->next[i];
}
}
for (int i = 0; i <= priority; i++) {
node->next[i] = current->next[i];
node->prev[i] = current;
current->next[i]->prev[i] = node;
current->next[i] = node;
}
}
int Dequeue() {
if (IsEmpty()) {
cout << "PriorityQueue is empty." << endl;
return INT_MIN; // or any other sentinel value
}
// Find and remove the highest priority item
Node* current = head->next[MAXIMUM_ALLOWED_LEVELS];
int data = current->data;
for (int i = current->priority; i >= 0; i--) {
current->prev[i]->next[i] = current->next[i];
current->next[i]->prev[i] = current->prev[i];
delete current;
}
return data;
}
bool IsEmpty() const {
return head->next[0] == tail;
}
// Add this member function to the PriorityQueue class
};
#endif
So far what l have done is
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)
but l am having trouble create a process method that does the following, please asist in c++
1.When a priority queue is processed, all higher priority items are
processed before lower priority items
2 Once an item is processed it is removed from the SkipList
3. The Process method must output the data values in the order
they were processed
4. Display the skip list from highest level to lowest level to check
your code

More Related Content

Similar to Double linked list header file below for FYI#include iostream.pdf

CODE Data Structures
CODE Data StructuresCODE Data Structures
CODE Data Structures
Sonia Pahuja
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
angelsfashion1
 
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
mail931892
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
FOREVERPRODUCTCHD
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
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
arjuncp10
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
 
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
fastechsrv
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
angelsfashion1
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklistritu1806
 
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
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
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
anwarsadath111
 
Linked lists
Linked listsLinked lists
Linked lists
George Scott IV
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 

Similar to Double linked list header file below for FYI#include iostream.pdf (20)

Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
CODE Data Structures
CODE Data StructuresCODE Data Structures
CODE Data Structures
 
C++ Program to Implement Singly Linked List #includeiostream.pdf
 C++ Program to Implement Singly Linked List #includeiostream.pdf C++ Program to Implement Singly Linked List #includeiostream.pdf
C++ Program to Implement Singly Linked List #includeiostream.pdf
 
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
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdfimplement the ListLinked ADT (the declaration is given in ListLinked.pdf
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.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
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
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
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
 
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
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
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
 
Linked lists
Linked listsLinked lists
Linked lists
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 

More from facevenky

Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdfFlag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
facevenky
 
Exercise 3 You are to code some simple music player application .pdf
Exercise 3  You are to code some simple music player application .pdfExercise 3  You are to code some simple music player application .pdf
Exercise 3 You are to code some simple music player application .pdf
facevenky
 
Fiancial Statements. South Sea Baubles has the following (incomplete.pdf
Fiancial Statements. South Sea Baubles has the following (incomplete.pdfFiancial Statements. South Sea Baubles has the following (incomplete.pdf
Fiancial Statements. South Sea Baubles has the following (incomplete.pdf
facevenky
 
Explore how the shift to digital platforms and online interactions has.pdf
Explore how the shift to digital platforms and online interactions has.pdfExplore how the shift to digital platforms and online interactions has.pdf
Explore how the shift to digital platforms and online interactions has.pdf
facevenky
 
Exercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdfExercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdf
facevenky
 
Electronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdfElectronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdf
facevenky
 
Execution Steps of Building the Inverted Index is shown as below Exec.pdf
Execution Steps of Building the Inverted Index is shown as below Exec.pdfExecution Steps of Building the Inverted Index is shown as below Exec.pdf
Execution Steps of Building the Inverted Index is shown as below Exec.pdf
facevenky
 
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdf
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdfElicitation TechniquesSeeking help for Elicitation plan for projec.pdf
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdf
facevenky
 
Draw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdfDraw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdf
facevenky
 
Do the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdfDo the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdf
facevenky
 
Digital Communication SystemsObjectives 1 To be able to demons.pdf
Digital Communication SystemsObjectives 1 To be able to demons.pdfDigital Communication SystemsObjectives 1 To be able to demons.pdf
Digital Communication SystemsObjectives 1 To be able to demons.pdf
facevenky
 
Diagonal communicationa) is the traditional flow of communication .pdf
Diagonal communicationa) is the traditional flow of communication .pdfDiagonal communicationa) is the traditional flow of communication .pdf
Diagonal communicationa) is the traditional flow of communication .pdf
facevenky
 
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdfDepicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
facevenky
 
Create a diagram for the following scenario The music streaming serv.pdf
Create a diagram for the following scenario The music streaming serv.pdfCreate a diagram for the following scenario The music streaming serv.pdf
Create a diagram for the following scenario The music streaming serv.pdf
facevenky
 
Create a function that will read the saved projects from localStorag.pdf
Create a function that will read the saved projects from localStorag.pdfCreate a function that will read the saved projects from localStorag.pdf
Create a function that will read the saved projects from localStorag.pdf
facevenky
 
Dawn Company general ledger shows the following account balances amo.pdf
Dawn Company general ledger shows the following account balances amo.pdfDawn Company general ledger shows the following account balances amo.pdf
Dawn Company general ledger shows the following account balances amo.pdf
facevenky
 
Create a class Person with two instance variables of type String cal.pdf
Create a class Person with two instance variables of type String cal.pdfCreate a class Person with two instance variables of type String cal.pdf
Create a class Person with two instance variables of type String cal.pdf
facevenky
 
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdf
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdfDave and his friend Stewart each owns 50 percent of KBS. During the .pdf
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdf
facevenky
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
facevenky
 
Contreras article is about different reforms that have been introdu.pdf
Contreras article is about different reforms that have been introdu.pdfContreras article is about different reforms that have been introdu.pdf
Contreras article is about different reforms that have been introdu.pdf
facevenky
 

More from facevenky (20)

Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdfFlag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
 
Exercise 3 You are to code some simple music player application .pdf
Exercise 3  You are to code some simple music player application .pdfExercise 3  You are to code some simple music player application .pdf
Exercise 3 You are to code some simple music player application .pdf
 
Fiancial Statements. South Sea Baubles has the following (incomplete.pdf
Fiancial Statements. South Sea Baubles has the following (incomplete.pdfFiancial Statements. South Sea Baubles has the following (incomplete.pdf
Fiancial Statements. South Sea Baubles has the following (incomplete.pdf
 
Explore how the shift to digital platforms and online interactions has.pdf
Explore how the shift to digital platforms and online interactions has.pdfExplore how the shift to digital platforms and online interactions has.pdf
Explore how the shift to digital platforms and online interactions has.pdf
 
Exercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdfExercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdf
 
Electronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdfElectronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdf
 
Execution Steps of Building the Inverted Index is shown as below Exec.pdf
Execution Steps of Building the Inverted Index is shown as below Exec.pdfExecution Steps of Building the Inverted Index is shown as below Exec.pdf
Execution Steps of Building the Inverted Index is shown as below Exec.pdf
 
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdf
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdfElicitation TechniquesSeeking help for Elicitation plan for projec.pdf
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdf
 
Draw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdfDraw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdf
 
Do the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdfDo the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdf
 
Digital Communication SystemsObjectives 1 To be able to demons.pdf
Digital Communication SystemsObjectives 1 To be able to demons.pdfDigital Communication SystemsObjectives 1 To be able to demons.pdf
Digital Communication SystemsObjectives 1 To be able to demons.pdf
 
Diagonal communicationa) is the traditional flow of communication .pdf
Diagonal communicationa) is the traditional flow of communication .pdfDiagonal communicationa) is the traditional flow of communication .pdf
Diagonal communicationa) is the traditional flow of communication .pdf
 
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdfDepicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
 
Create a diagram for the following scenario The music streaming serv.pdf
Create a diagram for the following scenario The music streaming serv.pdfCreate a diagram for the following scenario The music streaming serv.pdf
Create a diagram for the following scenario The music streaming serv.pdf
 
Create a function that will read the saved projects from localStorag.pdf
Create a function that will read the saved projects from localStorag.pdfCreate a function that will read the saved projects from localStorag.pdf
Create a function that will read the saved projects from localStorag.pdf
 
Dawn Company general ledger shows the following account balances amo.pdf
Dawn Company general ledger shows the following account balances amo.pdfDawn Company general ledger shows the following account balances amo.pdf
Dawn Company general ledger shows the following account balances amo.pdf
 
Create a class Person with two instance variables of type String cal.pdf
Create a class Person with two instance variables of type String cal.pdfCreate a class Person with two instance variables of type String cal.pdf
Create a class Person with two instance variables of type String cal.pdf
 
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdf
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdfDave and his friend Stewart each owns 50 percent of KBS. During the .pdf
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdf
 
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdfCopy your completed LinkedList class from Lab 3 into the LinkedList..pdf
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf
 
Contreras article is about different reforms that have been introdu.pdf
Contreras article is about different reforms that have been introdu.pdfContreras article is about different reforms that have been introdu.pdf
Contreras article is about different reforms that have been introdu.pdf
 

Recently uploaded

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
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
kaushalkr1407
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
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
TechSoup
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
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
Vivekanand Anglo Vedic Academy
 
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
Jisc
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
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
Celine George
 

Recently uploaded (20)

Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
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
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
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
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
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
 
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
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
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
 

Double linked list header file below for FYI#include iostream.pdf

  • 1. Double linked list header file below for FYI #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 PriorityQueue header file code below
  • 6. #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) {
  • 7. 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); } ~PriorityQueue() { Node* current = head; while (current) { Node* nextNode = current->next[0]; delete current; current = nextNode; } } void Enqueue(int data, int priority) { Node* node = new Node(data, priority); Node* current = head; for (int i = MAXIMUM_ALLOWED_LEVELS; i >= 0; i--) { while (current->next[i]->priority < priority) { current = current->next[i]; } } for (int i = 0; i <= priority; i++) { node->next[i] = current->next[i]; node->prev[i] = current; current->next[i]->prev[i] = node; current->next[i] = node; } } int Dequeue() { if (IsEmpty()) { cout << "PriorityQueue is empty." << endl; return INT_MIN; // or any other sentinel value
  • 8. } // Find and remove the highest priority item Node* current = head->next[MAXIMUM_ALLOWED_LEVELS]; int data = current->data; for (int i = current->priority; i >= 0; i--) { current->prev[i]->next[i] = current->next[i]; current->next[i]->prev[i] = current->prev[i]; delete current; } return data; } bool IsEmpty() const { return head->next[0] == tail; } // Add this member function to the PriorityQueue class }; #endif So far what l have done is 1. When new item is being enqueued set its data and priority to random integers (priority is a random integer between 0 and
  • 9. MAXIMUM_ALLOWED_LEVEL_INDEX which is a property of the SkipList class) but l am having trouble create a process method that does the following, please asist in c++ 1.When a priority queue is processed, all higher priority items are processed before lower priority items 2 Once an item is processed it is removed from the SkipList 3. The Process method must output the data values in the order they were processed 4. Display the skip list from highest level to lowest level to check your code