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
Ad

More Related Content

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

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

Recently uploaded (20)

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 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
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
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
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
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
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
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
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
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
 
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
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
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.
 
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
 
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 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
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
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
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Contact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: OptometryContact Lens:::: An Overview.pptx.: Optometry
Contact Lens:::: An Overview.pptx.: Optometry
MushahidRaza8
 
Real GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for SuccessReal GitHub Copilot Exam Dumps for Success
Real GitHub Copilot Exam Dumps for Success
Mark Soia
 
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
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
dynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south Indiadynastic art of the Pallava dynasty south India
dynastic art of the Pallava dynasty south India
PrachiSontakke5
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
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
 
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
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
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
 
Ad

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