473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Ternary Heapsort algorithm

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
4 4305
sicarie
4,677 Expert Mod 4TB
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
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
oler1s
671 Expert 512MB
} This is what i made
but i think it s wrong
Ok. I wish you luck in fixing your mistakes.
Nov 8 '08 #4
TamusJRoyce
110 100+
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,

TamusJRoyce

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

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

Similar topics

5
by: why | last post by:
Hi, just been curious. i have learn that quicksorting algorithm is more widely used then heapsort, despite having the same performance indication of O(n log n) anyone knows why? newbie
6
by: praba kar | last post by:
Dear All, I am new to Python. I want to know how to work with ternary operator in Python. I cannot find any ternary operator in Python. So Kindly clear my doubt regarding this ...
3
by: PWalker | last post by:
Hi, I have written code that I would like to optimize. I need to push it to the limit interms of speed as the accuracy of results are proportional to runtime. First off, would anyone know any...
7
by: Bonj | last post by:
In making a ternary search tree to identify as fast as possible the type of word passed in to the algorithm, for instance sp_help -> 1 (procedures), select -> 2 (keywords), sysobjects -> 3 (system...
51
by: Joerg Schoen | last post by:
Hi folks! Everyone knows how to sort arrays (e. g. quicksort, heapsort etc.) For linked lists, mergesort is the typical choice. While I was looking for a optimized implementation of mergesort...
0
by: JosAH | last post by:
Greetings, I was asked to write a Tip Of the Week; so here goes: a lot of topics are started here in this forum (and a lot of other forums too) mentioning a problem about sorting data. ...
5
by: PerlPhi | last post by:
hi,,, while ago i was wondering why do some programmers rarely uses the ternary operator. wherein it is less typing indeed. i believe in the classic virtue of Perl which is laziness. well let me show...
41
by: istillshine | last post by:
Questions for the major contributors to comp.lang.c. What C books do you have? What C books have you read? Which algorithm book is your favorite? What resources that you find...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...
0
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...

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.