Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic Net Database Programming

Authors: Rod Stephens

1st Edition

0789726815, 978-0789726810

More Books

Students also viewed these Databases questions

Question

Question How are IRAs treated for state tax law purposes?

Answered: 1 week ago