473,791 Members | 2,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A little help using some functions for a Heap

10 New Member
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)(Da taType& 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 getLeftChildInd ex(int nodeIndex);
inline int getRightChildIn dex(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(Da taType x)
{

if(size>=max_si ze)
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(arr ay[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
1 1662
JosAH
11,448 Recognized Expert MVP
According to your own function declaration the parameter to the 'insert' function
should be of type 'DataType'.

kind regards,

Jos
Apr 14 '07 #2

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

Similar topics

0
1649
by: Robert Potthast | last post by:
Hello, I want to make my garbage collector more safe. To make it more safe I need to know if an object has been allocated on the stack or on the heap using the operator new. My garbage collector uses a mixture of reference counting and smart pointers. I have got a base class ("Object") which handles all the memory management stuff. I have worked out different approaches to pass the info to my base class (won't name all):
3
5193
by: gary | last post by:
Hi, 1. About all C/C++ compilers, Does stack increase from high address to low address and heap grow increase from low to high? What on earth decides their increase direction, CPU architecture, OS or compiler? 2. In GNU gcc, { int a = {0, 1, 2, 3, 4}; bool b; float c; for (int i = 0; i < 5; i++) {
20
3504
by: Sushil | last post by:
Hi gurus I was reading FAQ "alloca cannot be written portably, and is difficult to implement on machines without a conventional stack." I understand that the standard does not mandate "heap" or "stack" I'm curious to know the implemenations which dont have stack or heap.
9
2215
by: gold | last post by:
Hello all, I want know abt wht kind of datastructures using both C & C++ internally. Some were said heap, others said tree anyone can explain brief?
19
4262
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
7
4451
by: Ritu | last post by:
Hi All, Can any body please tell me how i can write a device driver using CSharp. Thanks, Ritu
3
3232
by: doubts | last post by:
Hi all, I am trying to convert my bulk of code from VC++ 6.0 to VC++.Net. when using std::string type variable, the application causes exception at one instance and does not cause an exception at other. i have two functions in the same .cpp file //exception occurs at this function void call(const char* var2 ) {
52
3403
by: ¬a\\/b | last post by:
is it possible that a malloc function that use a nobody student is better than all yours :) How many errors do you see? Bug1: memory<13MB Bug2: it seems do you have to write you own sprintf "Ps_m" Ps_m(char* out, int len, char* fmt, ...)
71
19140
by: desktop | last post by:
I have read in Bjarne Stroustrup that using malloc and free should be avoided in C++ because they deal with uninitialized memory and one should instead use new and delete. But why is that a problem? I cannot see why using malloc instead of new does not give the same result.
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4109
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3713
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2913
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.