By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,310 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,310 IT Pros & Developers. It's quick & easy.

A little help using some functions for a Heap

P: 10
Hi, I have a question regarding the use of a couple functions I have for an assignment.. first here is the header file that im trying to use
//---------------------------------------------------------------------------------
struct DataType
{
int key;
string name;
};


class Heap
{
public:
bool insert(DataType inData);
bool retrieve (DataType& outData);
void traverse (void(*doit)(DataType& outData));
bool empty();
bool full();
void dump();
void print(DataType x);
Heap(int maxHeapSize=100);




private:
int size;
int max_size;
DataType* array;
bool reheapUp(int nodeIndex);
bool reheapDown(int nodeIndex);
void swap (DataType& x, DataType& y);
inline int getLeftChildIndex(int nodeIndex);
inline int getRightChildIndex(int nodeIndex);
inline int getParentIndex(int nodeIndex);
};
//--------------------------------------------------------------------------------------------
and here is the function I am having a problem with, all I would like to know is how do I go about using this function in the main() program, what parameter would I have to enter into the function call so that it inserts a new number(int) into the heap(which has been formed by using an array implementation).

bool Heap::insert(DataType x)
{

if(size>=max_size)
return false;

array[size++]=x;
reheapUp(size-1);
return true;
}

I want to be able to do something along the lines of
heap.insert(5);//if I wanted to add the int 5 to the heap
or maybe I need to do something like,
heap.insert(array[5])?
as a call in the main function. I assume I need to change some things In the header file to be able to use this function in that way.

Any incite would be much appreciated, thanks!
Apr 13 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
According to your own function declaration the parameter to the 'insert' function
should be of type 'DataType'.

kind regards,

Jos
Apr 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.