SlideShare a Scribd company logo
Node file code below
#ifndef NODE_H
#define NODE_H
#include
using namespace std;
// the node
class Node{
public:
int value;
// Array of pointers to the next nodes (which may be located at various levels)
// next[i] is the next link for level i
// the size of this vector determines the number of levels that the current node is part of
vector next;
vector prev; // previous links for each level the node is part of
Node(int val, int level){
value = val;
next = vector(level+1, nullptr); // initialize array of pointers to nulls
prev = vector(level+1, nullptr); // initialize array of pointers to nulls
};
};
#endif
SKIPLIST.H FILE CODE BELOW
#include
#include
#include
#include
#include
#include
#include "Node.h"
#ifndef SKIPLIST_H
#define SKIPLIST_H
using namespace std;
class SkipList{
public:
// Maximum allowed level index
int MAXIMUM_ALLOWED_LEVEL_INDEX;
// current maximum level amongst the inserted nodes
int currentHighestLevelIndex;
// the head node's next links are connected to the first node at every level
Node *head;
Node* tail; // last node at every level
SkipList(int maxLevels){
MAXIMUM_ALLOWED_LEVEL_INDEX = maxLevels;
// initially we have the bottom-most level only
currentHighestLevelIndex = 0;
// create the header node, value is irrelevant (as long as it doesn't match an inserted value -
NO REPEATS), number of next links is important (initially this node is the first node at every
level)
head = new Node(INT_MIN, MAXIMUM_ALLOWED_LEVEL_INDEX);
tail = new Node(INT_MAX, MAXIMUM_ALLOWED_LEVEL_INDEX); // last nodes at
each level
// connect head to tail at every level
for(int i = 0; i <= MAXIMUM_ALLOWED_LEVEL_INDEX; i++){
head->next[i] = tail; // head's prev is null
tail->prev[i] = head; // tail's next is null
}
}
int RandomLevel(){
float probablity = (float)rand()/RAND_MAX; // flip a coin
int lvl = 0;
while (probablity < 0.5 && lvl < MAXIMUM_ALLOWED_LEVEL_INDEX){
lvl++; // landed heads so increase level by 1
probablity = (float)rand()/RAND_MAX; // flip a coin again
}
return lvl;
}
Node* CreateNode(int value, int level){
// create a new node with next links for every level that this node will be part of
// it will use these links to connect to the next node at each level
return new Node(value, level);
}
void InsertElement(int value){
Node *current = head; // start at head node
vector update(MAXIMUM_ALLOWED_LEVEL_INDEX+1, nullptr); // this will hold the
nodes that need updating at every level after the insert takes place
for (int i = currentHighestLevelIndex; i >= 0; i--){ // start at the highest level and move
down so that more nodes may be skipped
// for level i, if value is to be inserted here then find out where (i.e. after which node)
while (current->next[i] != nullptr && current->next[i]->value < value){
current = current->next[i];
}
// found the node after which the value is to be placed at level i
update[i] = current;
// move down a level, if possible
}
// at level 0, where current is pointing to by the end of the preceding loop, move over one
node to the right where the value is to be inserted to see if the value already exists there (NO
REPEATS allowed)
current = current->next[0];
if (current == nullptr || current->value != value){
int ranLevel = RandomLevel(); // choose a random level upto where the new node will be
placed (starting from level 0)
if (ranLevel > currentHighestLevelIndex){
// if random level for current node is higher than the current maximum level for
existing nodes; then set head as the node after which the new value is to be inserted for each
level over current maximum to the level chosen for new value to be inserted (update currently
contains nulls for these level(s)).
for (int i = currentHighestLevelIndex+1; i <= ranLevel; i++){
update[i] = head;
}
// also change the current maximum level for the existing nodes
currentHighestLevelIndex = ranLevel;
}
// create new node with next links for every level from ranLevel to zero
Node* n = CreateNode(value, ranLevel);
// placing new node in the correct place at every level
for (int i = 0; i<=ranLevel; i++){
// n connects as a new node between update[i] and update[i]->next[i]
n->next[i] = update[i]->next[i];
n->prev[i] = update[i];
// update[i] connects to n (update[i] is the node before n)
update[i]->next[i] = n;
// n->next[i] (this was originally update[i]->next[i], the node that should be after n)
connects back to n
n->next[i]->prev[i] = n;
}
}
}
void Delete(int value){
// remove value from skip list (all levels) if it exists (output a message if it does not exist)
Node *current = head; // start at head node
vector update(MAXIMUM_ALLOWED_LEVEL_INDEX+1, nullptr); // this will hold the
nodes that need updating at every level after the delete takes place
for (int i = currentHighestLevelIndex; i >= 0; i--){ // start at the highest level and move
down so that more nodes may be skipped
// for level i, if value is to be deleted from here then find out where from (i.e. after which
node could it be)
while (current->next[i] != nullptr && current->next[i]->value < value){
current = current->next[i]; // moving right on level i
}
if(current->next[i] != nullptr && current->next[i]->value == value){
// found the node after which exists the target node (node that is to be deleted from
level i)
update[i] = current;
}
// move down a level, if possible
}
// at level 0, where current is pointing to by the end of the preceding loop, move over one
node to the right to see value exists there before we try to delete it
current = current->next[0];
if (current != nullptr && current->value == value){
// value exists at level 0, so delete it from all levels where it is located.
for (int i = 0; i <= currentHighestLevelIndex; i++){
if(update[i]){ // first we ensure that value exists at level i (otherwise update[i] will be
null)
// update[i] connects to the node after current (current->next[i])
update[i]->next[i] = current->next[i];
// current->next[i] (the node that should be after update[i]) connects back to
update[i]
current->next[i]->prev[i] = update[i];
// disconnect current from level i - are these necessary?
current->next[i] = nullptr;
current->prev[i] = nullptr;
}
}
// delete current
delete current;
// update currentHighestLevelIndex if necessary
while (currentHighestLevelIndex >= 0 && head->next[currentHighestLevelIndex] ==
tail){
currentHighestLevelIndex--;
}
}
else{
// if update[0] is nullptr then preceding loop was unable to find value at level 0
cout << "Value " << value << " does not exist in the skip list.n";
}
}
bool Search(int value){
// TO BE COMPLETED
// search for value in skip list and return true if it exists; false otherwise
Node *current = head; // start at head node
for (int i = currentHighestLevelIndex; i >= 0; i--){ // start at the highest level and move
down so that more nodes may be skipped
// for level i, keep moving right while values are less than what we are looking for (and if
it is possible to move any further right
while (current->next[i] != nullptr && current->next[i]->value < value){
current = current->next[i]; // moving right
}
if(current->next[i] != nullptr && current->next[i]->value == value){
return true; // found the value at level i
}
// move down a level, if possible
}
return false; // value not found, we are at level 0 and to the farthest right at level 0 (value
always exists at level 0 if in the list)
}
void ShowForward(){
cout << "Showing forward:n";
for (int i = currentHighestLevelIndex; i >= 0;i--){
Node *node = head->next[i];
cout << "Level " << i << ": ";
while (node != nullptr && node->next[i] != tail){
cout << node->value << " -> ";
node = node->next[i];
}
if(node){
cout << node->value << " .n";
}
else{
cout << " .n";
}
}
}
void ShowBackward(){
cout << "Showing backward:n";
for (int i = currentHighestLevelIndex; i >= 0;i--){
Node *node = tail->prev[i];
cout << "Level " << i << ": ";
while (node != nullptr && node->prev[i] != head){
cout << node->value << " -> ";
node = node->prev[i];
}
if(node){
cout << node->value << " .n";
}
else{
cout << " .n";
}
}
}
};
#endif
PRIORITYQ file code below
#ifndef PRIORITYQ_H
#define PRIORITYQ_H
#include
#include
#include
#include
#include "Skiplist.h"
using namespace std;
class PriorityQ{
public:
Node *head;
Node *tail;
int priority;
int maxlevel;
PriorityQ(int Level){
srand(time(0));
//priority = rand() % (Level-1);
maxlevel = Level-1;
head = new Node(INT_MIN, Level-1);
tail = new Node(INT_MAX, Level-1);
}
bool isEmpty() {
return head->next[0] == tail;
}
void enqueue(int data) {
priority = rand() % (maxlevel + 1);
//cout << "priority " << priority << endl;
Node *curr = head;
for (int i = maxlevel; i >= 0; i--) {
curr = head;
while (curr->next[i] != nullptr && curr->next[i]->value < data) {
curr = curr->next[i];
}
if (i <= priority) {
Node *newNode = new Node(data, i);
newNode->next[i] = curr->next[i];
curr->next[i] = newNode;
}
}
}
void dequeue(int value, int level) {
for (int i = level; i >= 0; i--) {
Node *curr = head->next[i];
while (curr->next[i] != nullptr && curr->value < value) {
if(curr->value == value){
Node *temp = curr;
curr->prev[i]->next[i] = curr->next[i];
curr->next[i]->prev[i]=curr->prev[i];
curr = curr->next[i];
delete temp;
}
curr = curr->next[i];
}
}
}
void process() {
for (int i = maxlevel; i >= 0; i--) {
Node *curr = head;
cout << "Process " << i << ": ";
while (curr->next[i] != tail) {
cout << curr->next[i]->value << ", ";
dequeue(curr->next[i]->value, i);
curr = curr->next[i];
}
}
}
void show(){
for (int i = maxlevel; i >= 0;i--){
Node *node = head->next[i];
cout << "Level " << i << ": ";
while (node != nullptr && node->next[i] != tail){
cout << node->value << " -> ";
node = node->next[i];
}
if(node){
cout << node->value << " .n";
}
else{
cout << " .n";
}
}
}
};
#endif
in my priorityq file code my process method is not working correctly, its outputting the below
Level 2: 5 -> 55 -> .
Level 1: 5 -> 10 -> 55 -> 1000 -> .
Level 0: 2 -> 5 -> 10 -> 22 -> 55 -> 700 -> 1000 -> .
Process 2: 5, 55,
WHEN l should be getting
Level 2: 5 -> 55 -> .
Level 1: 5 -> 10 -> 55 -> 1000 -> .
Level 0: 2 -> 5 -> 10 -> 22 -> 55 -> 700 -> 1000 -> .
Process 2: 5, 55,
Process 1: 10,1000
Process 0 2,22,700
please fix my process and dequeue code if you see the problem

More Related Content

Similar to Node file code below#ifndef NODE_H#define NODE_H#include .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
arjunstores123
 
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
 
#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
ajoy21
 
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
 
#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
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
fathimahardwareelect
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
Masud Parvaze
 
#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
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 
Im creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdfIm creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdf
arkmuzikllc
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
DaniyalAli81
 
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
 
Write an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfWrite an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdf
Arrowdeepak
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
Himadri Sen Gupta
 
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
vishalateen
 
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
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
amitbagga0808
 
Please correct my errors upvote Clears our entire .pdf
Please correct my errors upvote      Clears our entire .pdfPlease correct my errors upvote      Clears our entire .pdf
Please correct my errors upvote Clears our entire .pdf
kitty811
 
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
 
#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
 

Similar to Node file code below#ifndef NODE_H#define NODE_H#include .pdf (20)

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
 
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
 
#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
 
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
 
#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
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
 
#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 
Im creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdfIm creating a skip list program for my Algorithms and Advanced Data.pdf
Im creating a skip list program for my Algorithms and Advanced Data.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
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
 
Write an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdfWrite an algorithm that reads a list of integers from the keyboard, .pdf
Write an algorithm that reads a list of integers from the keyboard, .pdf
 
17 linkedlist (1)
17 linkedlist (1)17 linkedlist (1)
17 linkedlist (1)
 
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
 
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
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Please correct my errors upvote Clears our entire .pdf
Please correct my errors upvote      Clears our entire .pdfPlease correct my errors upvote      Clears our entire .pdf
Please correct my errors upvote Clears our entire .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
 
#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
 

More from contact41

Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdfNeed to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
contact41
 
Manufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdfManufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdf
contact41
 
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdfMake sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
contact41
 
John Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdfJohn Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdf
contact41
 
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdfJoe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
contact41
 
In the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdfIn the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdf
contact41
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 
Imagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdfImagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdf
contact41
 
In September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdfIn September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdf
contact41
 
Im writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdfIm writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdf
contact41
 
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdfImagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
contact41
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
contact41
 
I. Common stocks increase. III. Accounts .pdf
I.   Common stocks increase.                         III.  Accounts .pdfI.   Common stocks increase.                         III.  Accounts .pdf
I. Common stocks increase. III. Accounts .pdf
contact41
 
I. Inventories increase. III. Accounts rece.pdf
I.   Inventories increase.                     III.  Accounts rece.pdfI.   Inventories increase.                     III.  Accounts rece.pdf
I. Inventories increase. III. Accounts rece.pdf
contact41
 

More from contact41 (14)

Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdfNeed to elaborate on this discussion post Marvin Mower (MM) has t.pdf
Need to elaborate on this discussion post Marvin Mower (MM) has t.pdf
 
Manufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdfManufacturing and service operations can be divided into different t.pdf
Manufacturing and service operations can be divided into different t.pdf
 
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdfMake sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
Make sure its correct for a thumbs up! Thank you! 6. Suppose the qu.pdf
 
John Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdfJohn Stewart was a political candidate running for the Garden Hills .pdf
John Stewart was a political candidate running for the Garden Hills .pdf
 
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdfJoe and Jessie are married and have one dependent child, Lizzie. L.pdf
Joe and Jessie are married and have one dependent child, Lizzie. L.pdf
 
In the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdfIn the current ever-evolving landscape of higher education, the Univer.pdf
In the current ever-evolving landscape of higher education, the Univer.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
Imagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdfImagine youre part of a security team of a startup that is creating.pdf
Imagine youre part of a security team of a startup that is creating.pdf
 
In September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdfIn September 2016, the bodies of two children and their father were .pdf
In September 2016, the bodies of two children and their father were .pdf
 
Im writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdfIm writing an abstract class in java right now for this json file a.pdf
Im writing an abstract class in java right now for this json file a.pdf
 
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdfImagine you are a cybersecurity consultant tasked with designing aut.pdf
Imagine you are a cybersecurity consultant tasked with designing aut.pdf
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
I. Common stocks increase. III. Accounts .pdf
I.   Common stocks increase.                         III.  Accounts .pdfI.   Common stocks increase.                         III.  Accounts .pdf
I. Common stocks increase. III. Accounts .pdf
 
I. Inventories increase. III. Accounts rece.pdf
I.   Inventories increase.                     III.  Accounts rece.pdfI.   Inventories increase.                     III.  Accounts rece.pdf
I. Inventories increase. III. Accounts rece.pdf
 

Recently uploaded

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
siemaillard
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptxPrésentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
Présentationvvvvvvvvvvvvvvvvvvvvvvvvvvvv2.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 

Node file code below#ifndef NODE_H#define NODE_H#include .pdf

  • 1. Node file code below #ifndef NODE_H #define NODE_H #include using namespace std; // the node class Node{ public: int value; // Array of pointers to the next nodes (which may be located at various levels) // next[i] is the next link for level i // the size of this vector determines the number of levels that the current node is part of vector next; vector prev; // previous links for each level the node is part of Node(int val, int level){ value = val; next = vector(level+1, nullptr); // initialize array of pointers to nulls prev = vector(level+1, nullptr); // initialize array of pointers to nulls }; }; #endif SKIPLIST.H FILE CODE BELOW #include #include #include #include #include
  • 2. #include #include "Node.h" #ifndef SKIPLIST_H #define SKIPLIST_H using namespace std; class SkipList{ public: // Maximum allowed level index int MAXIMUM_ALLOWED_LEVEL_INDEX; // current maximum level amongst the inserted nodes int currentHighestLevelIndex; // the head node's next links are connected to the first node at every level Node *head; Node* tail; // last node at every level SkipList(int maxLevels){ MAXIMUM_ALLOWED_LEVEL_INDEX = maxLevels; // initially we have the bottom-most level only currentHighestLevelIndex = 0; // create the header node, value is irrelevant (as long as it doesn't match an inserted value - NO REPEATS), number of next links is important (initially this node is the first node at every level) head = new Node(INT_MIN, MAXIMUM_ALLOWED_LEVEL_INDEX);
  • 3. tail = new Node(INT_MAX, MAXIMUM_ALLOWED_LEVEL_INDEX); // last nodes at each level // connect head to tail at every level for(int i = 0; i <= MAXIMUM_ALLOWED_LEVEL_INDEX; i++){ head->next[i] = tail; // head's prev is null tail->prev[i] = head; // tail's next is null } } int RandomLevel(){ float probablity = (float)rand()/RAND_MAX; // flip a coin int lvl = 0; while (probablity < 0.5 && lvl < MAXIMUM_ALLOWED_LEVEL_INDEX){ lvl++; // landed heads so increase level by 1 probablity = (float)rand()/RAND_MAX; // flip a coin again } return lvl; } Node* CreateNode(int value, int level){ // create a new node with next links for every level that this node will be part of // it will use these links to connect to the next node at each level return new Node(value, level); } void InsertElement(int value){ Node *current = head; // start at head node vector update(MAXIMUM_ALLOWED_LEVEL_INDEX+1, nullptr); // this will hold the nodes that need updating at every level after the insert takes place for (int i = currentHighestLevelIndex; i >= 0; i--){ // start at the highest level and move down so that more nodes may be skipped // for level i, if value is to be inserted here then find out where (i.e. after which node) while (current->next[i] != nullptr && current->next[i]->value < value){
  • 4. current = current->next[i]; } // found the node after which the value is to be placed at level i update[i] = current; // move down a level, if possible } // at level 0, where current is pointing to by the end of the preceding loop, move over one node to the right where the value is to be inserted to see if the value already exists there (NO REPEATS allowed) current = current->next[0]; if (current == nullptr || current->value != value){ int ranLevel = RandomLevel(); // choose a random level upto where the new node will be placed (starting from level 0) if (ranLevel > currentHighestLevelIndex){ // if random level for current node is higher than the current maximum level for existing nodes; then set head as the node after which the new value is to be inserted for each level over current maximum to the level chosen for new value to be inserted (update currently contains nulls for these level(s)). for (int i = currentHighestLevelIndex+1; i <= ranLevel; i++){ update[i] = head; } // also change the current maximum level for the existing nodes currentHighestLevelIndex = ranLevel; } // create new node with next links for every level from ranLevel to zero Node* n = CreateNode(value, ranLevel); // placing new node in the correct place at every level for (int i = 0; i<=ranLevel; i++){ // n connects as a new node between update[i] and update[i]->next[i] n->next[i] = update[i]->next[i];
  • 5. n->prev[i] = update[i]; // update[i] connects to n (update[i] is the node before n) update[i]->next[i] = n; // n->next[i] (this was originally update[i]->next[i], the node that should be after n) connects back to n n->next[i]->prev[i] = n; } } } void Delete(int value){ // remove value from skip list (all levels) if it exists (output a message if it does not exist) Node *current = head; // start at head node vector update(MAXIMUM_ALLOWED_LEVEL_INDEX+1, nullptr); // this will hold the nodes that need updating at every level after the delete takes place for (int i = currentHighestLevelIndex; i >= 0; i--){ // start at the highest level and move down so that more nodes may be skipped // for level i, if value is to be deleted from here then find out where from (i.e. after which node could it be) while (current->next[i] != nullptr && current->next[i]->value < value){ current = current->next[i]; // moving right on level i } if(current->next[i] != nullptr && current->next[i]->value == value){ // found the node after which exists the target node (node that is to be deleted from level i) update[i] = current; } // move down a level, if possible } // at level 0, where current is pointing to by the end of the preceding loop, move over one node to the right to see value exists there before we try to delete it current = current->next[0];
  • 6. if (current != nullptr && current->value == value){ // value exists at level 0, so delete it from all levels where it is located. for (int i = 0; i <= currentHighestLevelIndex; i++){ if(update[i]){ // first we ensure that value exists at level i (otherwise update[i] will be null) // update[i] connects to the node after current (current->next[i]) update[i]->next[i] = current->next[i]; // current->next[i] (the node that should be after update[i]) connects back to update[i] current->next[i]->prev[i] = update[i]; // disconnect current from level i - are these necessary? current->next[i] = nullptr; current->prev[i] = nullptr; } } // delete current delete current; // update currentHighestLevelIndex if necessary while (currentHighestLevelIndex >= 0 && head->next[currentHighestLevelIndex] == tail){ currentHighestLevelIndex--; } } else{ // if update[0] is nullptr then preceding loop was unable to find value at level 0 cout << "Value " << value << " does not exist in the skip list.n"; } } bool Search(int value){ // TO BE COMPLETED // search for value in skip list and return true if it exists; false otherwise
  • 7. Node *current = head; // start at head node for (int i = currentHighestLevelIndex; i >= 0; i--){ // start at the highest level and move down so that more nodes may be skipped // for level i, keep moving right while values are less than what we are looking for (and if it is possible to move any further right while (current->next[i] != nullptr && current->next[i]->value < value){ current = current->next[i]; // moving right } if(current->next[i] != nullptr && current->next[i]->value == value){ return true; // found the value at level i } // move down a level, if possible } return false; // value not found, we are at level 0 and to the farthest right at level 0 (value always exists at level 0 if in the list) } void ShowForward(){ cout << "Showing forward:n"; for (int i = currentHighestLevelIndex; i >= 0;i--){ Node *node = head->next[i]; cout << "Level " << i << ": "; while (node != nullptr && node->next[i] != tail){ cout << node->value << " -> "; node = node->next[i]; } if(node){ cout << node->value << " .n"; } else{ cout << " .n"; } } }
  • 8. void ShowBackward(){ cout << "Showing backward:n"; for (int i = currentHighestLevelIndex; i >= 0;i--){ Node *node = tail->prev[i]; cout << "Level " << i << ": "; while (node != nullptr && node->prev[i] != head){ cout << node->value << " -> "; node = node->prev[i]; } if(node){ cout << node->value << " .n"; } else{ cout << " .n"; } } } }; #endif PRIORITYQ file code below #ifndef PRIORITYQ_H #define PRIORITYQ_H #include #include #include #include #include "Skiplist.h" using namespace std; class PriorityQ{ public: Node *head;
  • 9. Node *tail; int priority; int maxlevel; PriorityQ(int Level){ srand(time(0)); //priority = rand() % (Level-1); maxlevel = Level-1; head = new Node(INT_MIN, Level-1); tail = new Node(INT_MAX, Level-1); } bool isEmpty() { return head->next[0] == tail; } void enqueue(int data) { priority = rand() % (maxlevel + 1); //cout << "priority " << priority << endl; Node *curr = head; for (int i = maxlevel; i >= 0; i--) { curr = head; while (curr->next[i] != nullptr && curr->next[i]->value < data) { curr = curr->next[i]; } if (i <= priority) { Node *newNode = new Node(data, i); newNode->next[i] = curr->next[i]; curr->next[i] = newNode; } } } void dequeue(int value, int level) { for (int i = level; i >= 0; i--) { Node *curr = head->next[i]; while (curr->next[i] != nullptr && curr->value < value) {
  • 10. if(curr->value == value){ Node *temp = curr; curr->prev[i]->next[i] = curr->next[i]; curr->next[i]->prev[i]=curr->prev[i]; curr = curr->next[i]; delete temp; } curr = curr->next[i]; } } } void process() { for (int i = maxlevel; i >= 0; i--) { Node *curr = head; cout << "Process " << i << ": "; while (curr->next[i] != tail) { cout << curr->next[i]->value << ", "; dequeue(curr->next[i]->value, i); curr = curr->next[i]; } } } void show(){ for (int i = maxlevel; i >= 0;i--){ Node *node = head->next[i]; cout << "Level " << i << ": "; while (node != nullptr && node->next[i] != tail){ cout << node->value << " -> "; node = node->next[i]; } if(node){ cout << node->value << " .n"; } else{ cout << " .n";
  • 11. } } } }; #endif in my priorityq file code my process method is not working correctly, its outputting the below Level 2: 5 -> 55 -> . Level 1: 5 -> 10 -> 55 -> 1000 -> . Level 0: 2 -> 5 -> 10 -> 22 -> 55 -> 700 -> 1000 -> . Process 2: 5, 55, WHEN l should be getting Level 2: 5 -> 55 -> . Level 1: 5 -> 10 -> 55 -> 1000 -> . Level 0: 2 -> 5 -> 10 -> 22 -> 55 -> 700 -> 1000 -> . Process 2: 5, 55, Process 1: 10,1000 Process 0 2,22,700 please fix my process and dequeue code if you see the problem