Click here to Skip to main content
15,888,095 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Exception Handling using catch(...) Pin
vijay.victory5-Jul-09 23:27
vijay.victory5-Jul-09 23:27 
GeneralRe: Exception Handling using catch(...) Pin
Stuart Dootson5-Jul-09 23:45
professionalStuart Dootson5-Jul-09 23:45 
GeneralRe: Exception Handling using catch(...) Pin
vijay.victory6-Jul-09 0:13
vijay.victory6-Jul-09 0:13 
GeneralRe: Exception Handling using catch(...) Pin
vijay.victory6-Jul-09 0:44
vijay.victory6-Jul-09 0:44 
QuestionMFC multi-views print Pin
windyhigh5-Jul-09 18:19
windyhigh5-Jul-09 18:19 
AnswerRe: MFC multi-views print Pin
windyhigh5-Jul-09 22:05
windyhigh5-Jul-09 22:05 
QuestionDesign suggestion and the decorator design pattern Pin
The_Bob5-Jul-09 12:29
The_Bob5-Jul-09 12:29 
QuestionMy Heap implementation is not working...please have a look frnds.. Pin
pavarathyRock5-Jul-09 5:03
pavarathyRock5-Jul-09 5:03 
Hi Frnds,

I am trying to do the heap implementation.
I was following the algorithm explained in cormen....

#include "MyHeap.h"
void MyHeap::Build_Max_Heap(int * array, int length)
{
	for (int i= (length/2); i>=0 ; i--)
	{
		Max_heapify(array, i, length);
	}
}

void MyHeap::Max_heapify(int * array, int index, int length)
{
	int left = ((2 * index) + 1);
	int right = ((2 * index) + 2);
	int largest;
	if ((left <= length) && (array[left] > array[index]))
	{
		largest = left;
	}
	else
	{
		largest = index;
	}

	if ((right <= length) && (array[right] > array[largest]))
	{
		largest = right;
	}

	if (largest != index)
	{
		swap(array[largest], array[index]);
		Max_heapify(array, largest, length);
	}
}

void MyHeap::swap(int & a, int & b)
{
	int c = a;
	a = b;
	b = c;
}

void MyHeap::print(int * array, int length)
{
	for (int i = 0; i< length; i++)
	{
		cout<<array[i]<<"\t";
	}
}

int main()
{
	int array[] = {14, 10, 1, 8, 7, 9, 3, 2, 4, 16};
	MyHeap h;
	h.print(array, 10);
	h.Build_Max_Heap(array, 10);
	h.print(array, 10);

	int x;
	cin>>x;
	return(0);
}


For some input it is working.
For some it is not..

for the given input this is the output I am getting..

16 14 9 8 10 1 3 2 4 7


Thanks in advance...
AnswerRe: My Heap implementation is not working...please have a look frnds.. Pin
Iain Clarke, Warrior Programmer5-Jul-09 6:31
Iain Clarke, Warrior Programmer5-Jul-09 6:31 
AnswerRe: My Heap implementation is not working...please have a look frnds.. Pin
harold aptroot5-Jul-09 7:54
harold aptroot5-Jul-09 7:54 
GeneralRe: My Heap implementation is not working...please have a look frnds.. Pin
pavarathyRock6-Jul-09 5:22
pavarathyRock6-Jul-09 5:22 
GeneralRe: My Heap implementation is not working...please have a look frnds.. Pin
harold aptroot6-Jul-09 5:30
harold aptroot6-Jul-09 5:30 
GeneralRe: My Heap implementation is not working...please have a look frnds.. Pin
pavarathyRock6-Jul-09 6:11
pavarathyRock6-Jul-09 6:11 
GeneralRe: My Heap implementation is not working...please have a look frnds.. Pin
harold aptroot6-Jul-09 6:44
harold aptroot6-Jul-09 6:44 
AnswerRe: My Heap implementation is not working...please have a look frnds.. Pin
David Crow5-Jul-09 11:46
David Crow5-Jul-09 11:46 
Questionint in CListBox Pin
prithaa5-Jul-09 3:47
prithaa5-Jul-09 3:47 
AnswerRe: int in CListBox Pin
Sarath C5-Jul-09 4:26
Sarath C5-Jul-09 4:26 
GeneralRe: int in CListBox Pin
prithaa5-Jul-09 4:51
prithaa5-Jul-09 4:51 
GeneralRe: int in CListBox Pin
Sarath C5-Jul-09 5:16
Sarath C5-Jul-09 5:16 
GeneralRe: int in CListBox Pin
prithaa5-Jul-09 5:53
prithaa5-Jul-09 5:53 
QuestionDialog Box won't Resize Larger Pin
Tom Hubin4-Jul-09 22:21
Tom Hubin4-Jul-09 22:21 
AnswerRe: Dialog Box won't Resize Larger Pin
PJ Arends5-Jul-09 6:52
professionalPJ Arends5-Jul-09 6:52 
QuestionMemory Issues in developing 64 bit Driver in “Windows 64 bit standard edition” ? Pin
ta_isr4-Jul-09 22:01
ta_isr4-Jul-09 22:01 
QuestionRace Condition Pin
SNI4-Jul-09 20:53
SNI4-Jul-09 20:53 
AnswerRe: Race Condition Pin
killabyte5-Jul-09 1:57
killabyte5-Jul-09 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.