Source code needed

Scenario 2: Sorting Number
Write a C++ program (using function overloaded) to sort 10 integer values, or 10 long
values, or 10 double values. Number lists provide below:
valListInt = 23, 2, 34, 23, 43, 22, 32, 32, 43, 34
valListLong = 7000, 15, 34, 2373645, 43, 22, 9392929294, 46, 32, 111143
valListDbl = 23.3847239, 2.3974, 34.183734, 23.0, 43.36381, 22.3, 32.0, 32.1919,
43.938363, 34.38364

Please help me with this ...
I have to do this anyhow for my finals...
I had this lying around. You can overload the function easily enough. Stype needs a comparison if you don't use simple types like double. Edit, I stuck a 3 and a 7 in there for the tiny list size. Also keep the simple stuff here, the advanced stuff over in general ... duplicate posting isn't helpful. I don't remember exactly how this works, youll have to muddle it out and explain it to your professor, but its just a simple sort.


const int harr[] =
{
0, /*terminal condition for sort */
1, 3,7,
10,
53,
105,
542,
1047,
6239,
16256,
56720,
134096,
579823,
1000021,
5430201,
999999999 /*terminal condition for find index */
};


void ssort(stype *list , const int size);
void ssort(stype *list , const int size)
{
int i;
int j, dx = 1;

while(size > harr[dx])
{
dx++; /*get index in sequence, +1 */
}

while(--dx)
{
const int hdx = harr[dx]; //this guy is important!
for(i = hdx; i < size; i++)
{
const stype temp = list[i];
for(j = i; (j >= hdx) && (list[j-hdx] > temp); j -= hdx)
{
list[j] = list[j-hdx];
}
list[j] = temp;
}
}
}
Last edited on
@jonnin
Its not getting executed. I cannot compile it.
can u complete this source code ? I am so much in trouble because of this.
Please buddy?
it probably needs you to define stype.

try adding
typedef double stype ;
at the top, or something.

I am assuming you know how to wrap up a main to call it etc.

Last edited on
buddy I am still stuck on this ...
I am having problem with completing this code.

:'( :'(
which part is giving trouble? What did you try?
I did it :D
lol
yah finally I did it ...anyway thanks man for being there time to time
though I was annoying ...
I knew you could figure it out once you got into it. Now, can you explain it? Try stepping through it to see how it works, then see if you can figure out which sorting algorithm it is and what its big-o complexity might be etc. I normally won't give code until someone puts a little effort out there, but sorts are all over the web anyway so there is not stopping someone from lifting code for that. So instead I gave you something that is a bit of a puzzle to learn from. What is the purpose of the global array?

Last edited on
Topic archived. No new replies allowed.