Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Reheapdown

22/12/2020 Client: saad24vbs Deadline: 12 Hours

Lab8_PriorityQueue/Heap.h

#ifndef HEAPTYPE_H #define HEAPTYPE_H template <class ItemType> void swap(ItemType& one, ItemType& two); // Assumes ItemType is either a built-in simple type or a class // with overloaded relational operators. template<class ItemType> struct HeapType { void ReheapDown(int root, int bottom); void ReheapUp(int root, int bottom); //Extra HeapSort function with a variation of ReheapDown that takes three parameters. void HeapSort(int numValues); void ReheapDown(ItemType elements[], int root, int bottom); ItemType* elements; // Array to be allocated dynamically }; template <class ItemType> void Swap(ItemType& one, ItemType& two) { ItemType temp; temp = one; one = two; two = temp; } template<class ItemType> void HeapType<ItemType>::ReheapUp(int root, int bottom) // Post: Heap property is restored. { int parent; if (bottom > root) { parent = (bottom-1) / 2; if (elements[parent] < elements[bottom]) { Swap(elements[parent], elements[bottom]); ReheapUp(root, parent); } } } template<class ItemType> void HeapType<ItemType>::ReheapDown(int root, int bottom) // Post: Heap property is restored. { int maxChild; int rightChild; int leftChild; leftChild = root*2+1; rightChild = root*2+2; if (leftChild <= bottom) { if (leftChild == bottom) maxChild = leftChild; else { if (elements[leftChild] <= elements[rightChild]) maxChild = rightChild; else maxChild = leftChild; } if (elements[root] < elements[maxChild]) { Swap(elements[root], elements[maxChild]); ReheapDown(maxChild, bottom); } } } template<class ItemType> void HeapType<ItemType>::HeapSort(int numValues) // Pre: Struct HeapType is available. // Post: The elements in the array values are sorted by key. { int index; // Convert the array of values into a heap. for (index = numValues/2 - 1; index >= 0; index--) ReheapDown(elements, index, numValues-1); // Sort the array. for (index = numValues-1; index >=1; index--) { Swap(elements[0], elements[index]); ReheapDown(elements, 0, index-1); } } template<class ItemType> void HeapType<ItemType>::ReheapDown(ItemType elements[], int root, int bottom) // Post: Heap property is restored. { int maxChild; int rightChild; int leftChild; leftChild = root*2+1; rightChild = root*2+2; if (leftChild <= bottom) { if (leftChild == bottom) maxChild = leftChild; else { if (elements[leftChild] <= elements[rightChild]) maxChild = rightChild; else maxChild = leftChild; } if (elements[root] < elements[maxChild]) { Swap(elements[root], elements[maxChild]); ReheapDown(elements, maxChild, bottom); } } } #endif


Lab8_PriorityQueue/PQDr.cpp

Lab8_PriorityQueue/PQDr.cpp

//Ivan Temesvari

//4/1/2019

//Lab 8 driver

#include < iostream >

#include < fstream >

typedef int ItemType ;

#include "PQType.h"


using namespace std ;


int main ()

{

     //sample code for using a PQType

   ItemType item ;

   PQType < int > queue ( 50 );

  queue . Enqueue ( 5 );

  queue . Enqueue ( 10 );

  queue . Enqueue ( 4 );

  cout << queue << endl ;

   return 0 ;

}



Lab8_PriorityQueue/PQType.h

#ifndef PQTYPE_H #define PQTYPE_H // Definition of class PQType, which represents the Priority Queue ADT class FullPQ{}; class EmptyPQ{}; #include <iostream> #include "Heap.h" using namespace std; #define MAX_ITEMS 10 template<class ItemType> class PQType { public: PQType(); //default constructor PQType(int); // parameterized class constructor ~PQType(); // class destructor PQType operator=(const PQType& rhs); void MakeEmpty(); // Function: Initializes the queue to an empty state. // Post: Queue is empty. bool IsEmpty() const; // Function: Determines whether the queue is empty. // Post: Function value = (queue is empty) bool IsFull() const; // Function: Determines whether the queue is full. // Post: Function value = (queue is full) void Enqueue(ItemType newItem); // Function: Adds newItem to the rear of the queue. // Post: if (the priority queue is full) exception FullPQ is thrown; // else newItem is in the queue. void Dequeue(ItemType& item); // Function: Removes element with highest priority from the queue // and returns it in item. // Post: If (the priority queue is empty) exception EmptyPQ is thrown; // else highest priority element has been removed from queue. // item is a copy of removed element. template <class ItemPQ> friend ostream& operator<<(ostream& out, const PQType<ItemPQ>& pq); private: int length; HeapType<ItemType> items; int maxItems; }; template<class ItemType> PQType<ItemType>::PQType(){ maxItems = MAX_ITEMS; items.elements = new ItemType[maxItems]; length = 0; } template<class ItemType> PQType<ItemType>::PQType(int max) { maxItems = max; items.elements = new ItemType[maxItems]; length = 0; } template<class ItemType> PQType<ItemType> PQType<ItemType>::operator=(const PQType<ItemType>& rhs){ //assignment operator= if(this == &rhs){ return *this; } else{ //delete old contents of this delete [] items.elements; length = 0; maxItems = rhs.maxItems; items.elements = new ItemType[rhs.maxItems]; //copy new contents over to this from rhs int count = 0; while(count < rhs.length){ items.elements[count] = rhs.items.elements[count]; count++; } } return *this; } template<class ItemType> void PQType<ItemType>::MakeEmpty() { length = 0; } template<class ItemType> PQType<ItemType>::~PQType() { delete [] items.elements; } template<class ItemType> void PQType<ItemType>::Dequeue(ItemType& item) // Post: element with highest priority has been removed // from the queue; a copy is returned in item. { if (length == 0) throw EmptyPQ(); else { item = items.elements[0]; items.elements[0] = items.elements[length-1]; length--; items.ReheapDown(0, length-1); } } template<class ItemType> void PQType<ItemType>::Enqueue(ItemType newItem) // Post: newItem is in the queue. { if (length == maxItems) throw FullPQ(); else { length++; items.elements[length-1] = newItem; items.ReheapUp(0, length-1); } } template<class ItemType> bool PQType<ItemType>::IsFull() const // Post: Returns true if the queue is full; false, otherwise. { return length == maxItems; } template<class ItemType> bool PQType<ItemType>::IsEmpty() const // Post: Returns true if the queue is empty; false, otherwise. { return length == 0; } template <class ItemPQ> ostream& operator<<(ostream& out, const PQType<ItemPQ>& pq){ for(int i = 0; i < pq.length; i++){ out << pq.items.elements[i] << endl; } return out; } #endif


Applied Sciences

Architecture and Design

Biology

Business & Finance

Chemistry

Computer Science

Geography

Geology

Education

Engineering

English

Environmental science

Spanish

Government

History

Human Resource Management

Information Systems

Law

Literature

Mathematics

Nursing

Physics

Political Science

Psychology

Reading

Science

Social Science

Home

Blog

Archive

Contact

google+twitterfacebook

Copyright © 2019 HomeworkMarket.com

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

University Coursework Help
Top Essay Tutor
Helping Hand
Writer Writer Name Offer Chat
University Coursework Help

ONLINE

University Coursework Help

Hi dear, I am ready to do your homework in a reasonable price.

$102 Chat With Writer
Top Essay Tutor

ONLINE

Top Essay Tutor

I have more than 12 years of experience in managing online classes, exams, and quizzes on different websites like; Connect, McGraw-Hill, and Blackboard. I always provide a guarantee to my clients for their grades.

$105 Chat With Writer
Helping Hand

ONLINE

Helping Hand

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$100 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Proof variance of geometric distribution - Australia national medicines policy - Action research and minority problems - Uck london college moodle - How to calculate sound transmission class - What was the stated aim of robespierre and his supporters - Fire Protection Technology - Sans disaster recovery - Indian river citrus company case answers - Naive forecasting method excel - Safe handling of medication answers - Nurses scope of practice defined by ana - What are some of the major security threats caused by illegal immigration? - Www ilc org career matters - They say i say chapter 4 summary - Find the error in the following pseudocode - Diversity Issues in Criminal Justice _ Chapter 9. - Elearning dpcdsb student login - Kern's book warehouse distributes hardcover - Governmental accounting practice set province of europa solution - Medicaid discounting can cause hardships - Data security and privacy information technology - SOCW 6090 - Discussion: Applying Differential Diagnosis to Neurodevelopmental Disorders - Hacksaw ridge english - Ata paint technician online test - Cook hall howard university - Athlean x workout free download - Wjec level 3 criminology - Task risk assessment example - Miller dynasty 200 help codes - Netflix vision statement - Cyber crime trinidad number - Psy 315 week 1 worksheet - FINAL COURSE PROJECT MOKUL - Lorem ipsum - Four generic architectural components of a public communications network - Southwestern cafe - Barynya russian folk dance - Projecto o Dossier - [email protected] OPTION approved Abortion Pills +27835179056 in durban soweto springs mayfair benoni limpopo polokwane vaal - Concur expense administrator manual - Rpc style web service example - 12 volt continuous duty solenoid wiring diagram - Co nh3 6 cl3 - Chemistry mole conversions worksheet answers - Submission file format: Word document with all the answers, clearly identifying all steps, results, and including comments besides each answer. - Electrochemical cells lab answers experiment 21 - Being SMART - Health care to undocumented immigrants - How to get answers for math homework - How to calculate paint required for a wall - H2o2 to o2 half equation - An investment will pay at the end - Evidence based practice and case management - Intrinsic carrier concentration of silicon - Does technology make us more alone argumentative essay - 2200 ohm resistor color code - Classification dichotomous key of snowflakes a flurry of wintertime taxonomy - Physics questions 3 - If a typical firm reports 20 million - Lance vet st lucia - What does cvp mean in business - The day of destiny questions and answers - Financial reporting problem apple inc excel - Resolving forces in a truss - F75 85w 35 535 - 1899 coke bottle with cork - Economics and politics loughborough - 3 point scale examples - Marisol receives total employee benefits - Birtinya island master plan - Cheap seating area in a theatre crossword - Market research has revealed the following information about chocolate bars - External conflict man vs man - BMGT 305 - International hrm case study brunt hotels answers - How are accounts in the accounts payable ledger arranged - Paper - Please to refer to the uploaded paper - Gcf of 180 and 252 - Discussion: Preparation for Negotiation - Quantitative spectroscope and visible light lab - Hymenosporum flavum 'gold nugget not flowering - Everybody loves raymond amy slaps robert - Bhatiary golf and country club - Http ency education weebly com arabic html - In this assignment, you will evaluate a current organizational structure and recommend structural changes that can help address the concerns the organization identified regarding collaboration, communication, and autonomy. - 32 burley griffin drive maudsland - An important feature of a job order cost system is that each job - Bond energy of f2 - How to evaluate a lesson plan - PAPER – Construction Technology – CONSTRUCTION PROJECT MANAGEMENT - Hard rock case study - Np 31970 0 ps4 error code - Bend it like beckham themes - Dexter company applies the direct write-off method in accounting for uncollectible accounts. - DB.PP2 - 3 5 8 as a improper fraction - Difference between price ceiling and floor - Are cordyline australis poisonous to dogs