Question: I need help to complete this code: #include pqueue.h // constructor pqueue::pqueue() { count = 0; // no jobs yet } // destructor does nothing

I need help to complete this code:

I need help to complete this code: #include "pqueue.h" // constructor pqueue::pqueue()

#include "pqueue.h"

// constructor

pqueue::pqueue()

{ count = 0; // no jobs yet

}

// destructor does nothing

pqueue::~pqueue() {}

// Purpose: to add a job to a right place in the Pqueue

// Argument: j is the job priority number

void pqueue::insertjob(int j)

{

// ** add the job j at the rear

trickleup(); // moves the job to the right place

}

// Purpose: to print a job and reheapify the Pqueue

void pqueue::printjob()

{

cout

reheapify();

}

// Purpose: to display all jobs

void pqueue::displayAll()

{ cout

// ** loop to display jobs from slot 0 to slot count-1 horizontally

}

// Utility functions follow: ------------------

// Purpose: to make the very last job trickle up to the right location

void pqueue::trickleup()

{

int x = count-1; // the very last job location

// ** while x is > 0

// compare Q[x] with the parent and if the parent is bigger swap & update x. Otherwise stop.

// You can call getParent to get the location of the parent

}

// Purpose: find the location of the parent

// The child location is given. Need to call even.

int getParent(int child)

{ // ** return the parent location

}

// Purpose: is location i even? Important in finding its parent location

bool pqueue::even(int i)

{

if ((i % 2) == 0) return true; else return false; }

// Purpose: to reheapify the Pqueue after printing

void pqueue::reheapify()

{

Q[0] = Q[count-1]; // move the last job to the front

count--;

// ** start at the root and repeat the following:

// find the location of the smaller child if you have not fallen off the tree yet

// if the smaller child is smaller than the parent, swap

// else stop

}

// Purpose: to find the location of the smaller child

// where children at locations 2*i+1 and 2*i+2

int pqueue::getSmallerchild(int i)

{

// ** return the location of the smaller child

}

#include using namespace std; class pqueue private: int Qr101; int count; // array holding jobs - only priority numbers are stored // how many jobs are in the array // jobs are in slots through count-1 // Utility functions void reheapify // reheapify after printing /-involves moving the 1ast job to the front and trickling down int getSmallerchild(int); // return location of the smaller child I-compares L and R children of the given location void trickleup(); int getParent(int); // return the parent location given the child loc bool even(int); // trickling up after adding at the rear // is the number even? Needed to find the parent public: pqueue ) pqueue (); void insertjob(int); I/ supply the job priority number void printjob); void displayA1l) display al1 jobs //print a job il #include using namespace std; class pqueue private: int Qr101; int count; // array holding jobs - only priority numbers are stored // how many jobs are in the array // jobs are in slots through count-1 // Utility functions void reheapify // reheapify after printing /-involves moving the 1ast job to the front and trickling down int getSmallerchild(int); // return location of the smaller child I-compares L and R children of the given location void trickleup(); int getParent(int); // return the parent location given the child loc bool even(int); // trickling up after adding at the rear // is the number even? Needed to find the parent public: pqueue ) pqueue (); void insertjob(int); I/ supply the job priority number void printjob); void displayA1l) display al1 jobs //print a job il

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!