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++
C++ Write a C++ program that implements a tree using a linked representation Each node will...
C++ Write a C++ program that implements a tree using a linked representation Each node will contain a single integer data element. Initialize the tree to contain 10 nodes. The program should allow for the insertion and deletion of data. The program should allow the user to output data in Preorder, Inorder and Postorder.
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++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
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++ Build a binary tree using a binary tree class member function from the following array...
C++ Build a binary tree using a binary tree class member function from the following array of preorder traversal 3,9,20,15,7 and inorder traversal 9,3,15,20,7. Implement the constructor, destructor and all member functions including print postorder traversal of the binary tree.
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT