Purchase Solution

Write a C++ program to take n elements and insert them into a heap

Not what you're looking for?

Ask Custom Question

I need help with this assignment for my discussion forum. It says to write a program to take n elements and insert them into a heap one by one. Include a function to print out the elements in the heap.

Purchase this Solution

Solution Summary

The solution gives a complete C++ code to write a C++ program to take n elements and insert them into a heap one by one.

Solution Preview

#include <stdlib.h>

#include<iostream>
using namespace std;
#define MinPQSize (10)
#define MinData (-32767)
#define Error( Str ) FatalError( Str )
#define FatalError( Str ) fprintf( stderr, "%sn", Str ), exit( 1 )

struct HeapStruct
{
int Capacity;
int Size;
int *Elements;
};
// typedef int int;

struct HeapStruct;
typedef struct HeapStruct *PriorityQueue;

PriorityQueue Initialize( int MaxElements );
void Destroy( PriorityQueue H );
void MakeEmpty( PriorityQueue H );
void Insert( int X, PriorityQueue H );
int DeleteMin( PriorityQueue H );
int FindMin( PriorityQueue H );
int IsEmpty( PriorityQueue H );
int IsFull( PriorityQueue H );
int main(){
int i;
PriorityQueue p;
p = Initialize(10);
...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Tables

Have you never worked with Tables in Word 2010? Maybe it has been a while since you have used a Table in Word and you need to brush up on your skills. Several keywords and popular options are discussed as you go through this quiz.