Question

In: Computer Science

C++ Heap Tree:  Make a program called "priority_queue" that has the following operations using a heap and...

C++ Heap Tree:  Make a program called "priority_queue" that has the following operations using a heap and simulating a prioritized row of integers with higher priority value.

I would appreciate if someone could help me with this code

It has to include the following on the code:

push

Description: Add data to prioritized row

Entry: An integer, which you want to add to the prioritized row

Exit: Nothing
Precondition: n is an integer
Postcondition: The prioritized row contains new data.

pop -

Description: Remove the data with the highest priority from the prioritized row

Entry: Nothing
Exit: Nothing
Precondition: That the prioritized row contains at least 1 data.
Postcondition: The prioritized row is left without the data with the highest priority

top

Description: Returns the value of the data that is with the highest priority in the prioritized row.

Entry: Nothing
Output: The data that has the highest priority within the prioritized row
Precondition: That the prioritized row contains at least 1 data.
Postcondition: Nothing

empty

Description: Returns a boolean value saying if the prioritized row is empty or has data.

Entry:Nothing
Output: A boolean value that tells whether the prioritized row is empty or has data.
Precondition: Nothing.
Postcondition: Nothing

size

Description: Returns the amount of data that the prioritized row has

Entry :Nothing
Output :An integer value representing the amount of data in the prioritized row
Precondition: Nothing.
Postcondition: Nothing

It has to include the next class header

#ifndef MYHEAP_H

#define MYHEAP_H

class   MyHeap{

    private:

        int* values; //where the HEAP values ​​are going to be saved

        int size; //Represents how many values ​​the Heap has stored  

    public:

        MyHeap(); //Initialize the attributes. The values ​​attribute initializes it as an empty array size 7

        void push(int n); // Insert a value in the heap. Only when the new value does not fit in the array
// grow the array to size 2 * n + 1. (Dynamic expansion of the array)
// That is, if you already have the arrangement with 7 values ​​and you want to insert another value (The 8th)
// then the array is grown to size 15, the first 7 values ​​of the original array are copied
// and the 8th value is inserted.

                          

        void pop(); //A value is removed from the heap. It is never necessary to decrease the size of the array.

        int top(); //Return who is the next element to exit but without deleting it

        bool isEmpty(); //returns true if the heap is empty otherwise returns false

        int length(); //returns how many elements the heap is storing

    };

#endif

Solutions

Expert Solution


Related Solutions

Traversal tree program in c/c++
Traversal tree program in c/c++
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and...
Using Python, write a program that meets the following requirements: Make a list called sandwich_orders and fill it with the names of various sandwiches. Make an empty list called finished_sandwiches. Loop through the list of sandwich orders and spring a message for each order such as "I am working on your tuna sandwich" As each sandwich is made, move it to the list of finished sandwiches. After all the sandwiches have been made, print a message listing each sandwich that...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array...
C++(screenshot output please) Part 2 - Tree programs Program 1 Implement a tree using an array Program 2 Implement a tree using linked list - pointer Binary Tree Program 3 - Convert program 1 to a template
C++ tree program (do NOT use STRUCT, use classes)    Program 1 Implement a Binary tree...
C++ tree program (do NOT use STRUCT, use classes)    Program 1 Implement a Binary tree using an array    Program 2 Implement a tree using linked list - pointer Binary Tree    Program 3 - Convert program 1 to a template
Building a Priority Queue in C++ using a min-heap. Not using C++ Standard Template Library. Trying...
Building a Priority Queue in C++ using a min-heap. Not using C++ Standard Template Library. Trying to understand how this works. Thank you
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your...
C++ Memory Allocation: 1) Write a C++ program that allocates static, stack, & heap memory. Your program does not need to do anything else.  Indicate via comments where memory for at least one variable in each memory area is allocated. a) Write code that allocates static memory (only include one declaration): b) Write code that allocates stack memory (only include one declaration): c) Write code that allocates heap memory (only include one declaration): 2) Edit the C++ program below to include...
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
Make a program for LAGRANGE INTERPOLATION METHOD using C++ program and can be evaluated both polynomial...
Make a program for LAGRANGE INTERPOLATION METHOD using C++ program and can be evaluated both polynomial and Transcendental Functions.
c++ program You are to use a Heap data structure for this assignment I currently work...
c++ program You are to use a Heap data structure for this assignment I currently work for an investment/insurance company and I’m looking for clients to call, ones with funds.  I need to have a schedule that shows the list of customers to call and the order to be called.  The list of customers names and phone numbers are in the file ‘NamesAndPhoneV2.txt’.  A second file contains a net worth value for each client.  The files are separated for security and protection reasons, but...
Write a python program using the following requirements: Create a class called Sentence which has a...
Write a python program using the following requirements: Create a class called Sentence which has a constructor that takes a sentence string as input. The default value for the constructor should be an empty string The sentence must be a private attribute in the class contains the following class methods: get_all_words — Returns all the words in the sentence as a list get_word — Returns only the word at a particular index in the sentence Arguments: index set_word — Changes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT