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

Ternary Heapsort algorithm

P: 7
i need help to write the code for ternary fix down approach and ternary heapsort
can anyone give me link or just give me some help.
Nov 6 '08 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 2.5K+
P: 4,677
Sure, what do you need help with? If you post the portion of code you are having trouble with and a description of the issue, I'm sure someone can help.
Nov 6 '08 #2

P: 7
void fixDown3(Item a[], int k, int N)

{ int j;

while (3*k <= N)

{ c3++;

j = 3*k;

if (j < N)

{ if (a[3*k-1]>a[j]) j--;

if (a[3*k+1]>a[j]) j++;


if (!(a[k]< a[j])) break;

exch(a[k], a[j]); k = j;


}void heapsort3(Item a[], int l, int r)

{ int k, N = r-l+1;

for (k = (N+1)/3; k >=1; k--)

fixDown3(&a[0], k, N);

while (N > 1)


exch(a[1], a[N]);

fixDown3(&a[0], 1, --N);


} This is what i made
but i think it s wrong
Nov 8 '08 #3

Expert 100+
P: 671
} This is what i made
but i think it s wrong
Ok. I wish you luck in fixing your mistakes.
Nov 8 '08 #4

P: 110
I've got a pretty good link. The code here should help you out Heapsort.

The code here is a little easy to identify that it's not yours, so try changing it so it compiles in C++, but isn't recognizable as it's original code, pseudo. Combined it's code with your code to come up with unique code for solving this problem.

Also, a word of advice. Never ever use j, k or any single character as a variable name. Always spell out in descriptive words what it is. I usually use my first word as all lowercase, and all other words as initial caps. Like if I wanted a variable for counting through the indexes of an array called myArray, my variable would be: int myArrayIndex, or int myArrayCount, or something. Describe what each variable does, and document your code with comments as well!

I'm not trying to bash you, but I have no way of knowing what's going on in your code...

Post your code again after you do this by renaming your variables with understandable names, and commenting in what each part is trying to do--using my link to cheat/understand what's going on with your code.

Also tell us what class you are doing this for. Asking for help on homework without specifying it's homework is against forum rules :)

Hopefully Helpful,


"Writing code is like combining Algebra, Logic, and Book Writing with a much easier grammar to understand"
Nov 8 '08 #5

Post your reply

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