SlideShare a Scribd company logo
double linked list header file code
#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
Priority Queue header file code
#ifndef PRIORITYQ_H
#define PRIORITYQ_H
#include
#include
#include // for INT_MAX
#include // for rand()
#include
#include "doublySkiplist.h"
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
vector Process(SkipList& skipList) {
vector processedData;
// Process items from highest priority to lowest
for (int priority = MAXIMUM_ALLOWED_LEVELS; priority >= 0; priority--) {
Node* current = head->next[priority];
while (current->data != INT_MAX) {
int data = current->data;
// Process the item by removing it from the SkipList
skipList.Delete(data);
// Remove the item from the PriorityQueue
Node* temp = current;
current = current->next[priority];
for (int i = temp->priority; i >= 0; i--) {
temp->prev[i]->next[i] = temp->next[i];
temp->next[i]->prev[i] = temp->prev[i];
}
delete temp;
// Add the processed data to the result
processedData.push_back(data);
}
}
// Display the SkipList from highest level to lowest level
skipList.ShowBackwards();
return processedData;
}
};
#endif
main.cpp code file below
#include
#include
#include
#include "PriorityQ.h"
#include "doublyskiplist.h"
int main(){
srand(static_cast(time(nullptr)));
PriorityQueue queue(3);
SkipList q(3);
queue.Enqueue(5,0);
queue.Enqueue(2,1);
queue.Enqueue(3,2);
//queue.Dequeue();
//queue.ShowQueue();
queue.Process(q);
return 0;
}
l am trying to complete the below task
The priority queue holds data in a skip list where each node is doubly
linked at every level
1. Each node in the skip list contains an integer data, a non-
negative integer priority (this will also be the level index of the
node in the skiplist once inserted, default 0 because every
node must be part of level 0), a vector of next links and a
vector of previous links where the number of links in each
vector determines how many levels the node is part of.
1. Maximum value for priority is the maximum allowed
level for the skip list, minimum value is 0
Add methods Enqueue, Dequeue, Process to the Priority Queue class
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)
Priority of a node determines its level in the skiplist (no coin tosses)
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
Can you tell me why code doesn't output anything
Ad

More Related Content

Similar to double linked list header file code#include iostream#include.pdf (20)

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
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
Masud Parvaze
 
Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............
XEON14
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
Chaitanya Kn
 
#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
 
#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
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
Aakash deep Singhal
 
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
arjunstores123
 
ISCP internal.pdf
ISCP internal.pdfISCP internal.pdf
ISCP internal.pdf
GANDHAMKUMAR2
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
sooryasalini
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
illyasraja7
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
#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
ajoy21
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
Sarmad Baloch
 
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
 
3.linked list
3.linked list3.linked list
3.linked list
Chandan Singh
 
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
 
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
 
Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............Bsf23006565 dsa 3rd assignment.docx............
Bsf23006565 dsa 3rd assignment.docx............
XEON14
 
#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
 
#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
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
Aakash deep Singhal
 
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
arjunstores123
 
Please refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdfPlease refer this solution. This is working file for IntegersHeade.pdf
Please refer this solution. This is working file for IntegersHeade.pdf
sooryasalini
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
Given the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdfGiven the following codepackage data1;import java.util.;p.pdf
Given the following codepackage data1;import java.util.;p.pdf
illyasraja7
 
#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
ajoy21
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
Sarmad Baloch
 
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
 

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

Recently uploaded (20)

Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdfAPM Midlands Region April 2025 Sacha Hind Circulated.pdf
APM Midlands Region April 2025 Sacha Hind Circulated.pdf
Association for Project Management
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18How to Manage Purchase Alternatives in Odoo 18
How to Manage Purchase Alternatives in Odoo 18
Celine George
 
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdfIntroduction-to-Communication-and-Media-Studies-1736283331.pdf
Introduction-to-Communication-and-Media-Studies-1736283331.pdf
james5028
 
Geography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjectsGeography Sem II Unit 1C Correlation of Geography with other school subjects
Geography Sem II Unit 1C Correlation of Geography with other school subjects
ProfDrShaikhImran
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
BỘ ĐỀ TUYỂN SINH VÀO LỚP 10 TIẾNG ANH - 25 ĐỀ THI BÁM SÁT CẤU TRÚC MỚI NHẤT, ...
Nguyen Thanh Tu Collection
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Ad

double linked list header file code#include iostream#include.pdf

  • 1. double linked list header file code #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 Priority Queue header file code #ifndef PRIORITYQ_H
  • 6. #define PRIORITYQ_H #include #include #include // for INT_MAX #include // for rand() #include #include "doublySkiplist.h" 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);
  • 7. 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 vector Process(SkipList& skipList) { vector processedData; // Process items from highest priority to lowest for (int priority = MAXIMUM_ALLOWED_LEVELS; priority >= 0; priority--) { Node* current = head->next[priority]; while (current->data != INT_MAX) { int data = current->data; // Process the item by removing it from the SkipList skipList.Delete(data);
  • 9. // Remove the item from the PriorityQueue Node* temp = current; current = current->next[priority]; for (int i = temp->priority; i >= 0; i--) { temp->prev[i]->next[i] = temp->next[i]; temp->next[i]->prev[i] = temp->prev[i]; } delete temp; // Add the processed data to the result processedData.push_back(data); } } // Display the SkipList from highest level to lowest level skipList.ShowBackwards(); return processedData; } }; #endif main.cpp code file below #include #include #include #include "PriorityQ.h" #include "doublyskiplist.h" int main(){ srand(static_cast(time(nullptr))); PriorityQueue queue(3); SkipList q(3);
  • 10. queue.Enqueue(5,0); queue.Enqueue(2,1); queue.Enqueue(3,2); //queue.Dequeue(); //queue.ShowQueue(); queue.Process(q); return 0; } l am trying to complete the below task The priority queue holds data in a skip list where each node is doubly linked at every level 1. Each node in the skip list contains an integer data, a non- negative integer priority (this will also be the level index of the node in the skiplist once inserted, default 0 because every node must be part of level 0), a vector of next links and a vector of previous links where the number of links in each vector determines how many levels the node is part of. 1. Maximum value for priority is the maximum allowed level for the skip list, minimum value is 0 Add methods Enqueue, Dequeue, Process to the Priority Queue class 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) Priority of a node determines its level in the skiplist (no coin tosses) 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
  • 11. 4. Display the skip list from highest level to lowest level to check your code Can you tell me why code doesn't output anything