The best result till now is this:
http://en.wikibooks.org/wiki/Algorithm_implementation/Sorting/Heapsort
Thanks for your replies though.
Type: Posts; User: myle
The best result till now is this:
http://en.wikibooks.org/wiki/Algorithm_implementation/Sorting/Heapsort
Thanks for your replies though.
Where can I found a good implementation of heapsort? (I don't care if it's C++ or C)
Google didn't help me a lot. It would be ideal to find the implementation that is used by some efficient library,...
and keep in mind that the "random" numbers from the rand() follow a uniform distribution.
great tool.
I would prefer:
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *ptr;
I'll keep it in mind Elysia.
Isn't there any speed trade-off using these two statements instead of one?
Thanks Salem. Breaking it up into pieces helped me to find the error.
The fscanf() was reading the new line character and not the next line.
The code which does the work is:
fscanf(fp,...
The contents of the file are:
dim 400
epsilon 0.001
....
the code is:
// read the dimension of the table
I am not sure if this counts as an error in valgrind:
Thread 3:
==16388== Invalid read of size 4
==16388== at 0x40151F3: (within /lib/ld-2.7.so)
==16388== by 0x4005C69: (within...
You can't use the & operator on doubles.
An explanation here would be more useful than the solution or at least a hint were I can find some more info. Furthemore, as it is, it doesn't compile on gcc.
off topic:
@cpjust: Doing something...
Problem solved.
I have found the error. The swapping had been done fine. The problem was in the initialization of the two arrays. I wasn't careful with the values at the first and last row/column.
Indeed. You are right. Sometimes I am such an idiot.
My best try so far, still slower than the standard implementation:
double inline absolute(double number)
{
//printf("%f ", number);
...
Thanks!
The solution is:
double absolute(double number)
{
//printf("%f ", number);
unsigned long long* x = (unsigned long long*)&number;
*x &= 0x7fffffffffffffff;
Each iteration alters the values of after and only after, and then I calculate the maximum difference with the previous values. So, I don't care if it's not exactly the same (and it's not), I am...
What is the index error?
Valgrind doesn't return any warning for possible errors when I test my code.
...I print the results and are not the same. It's weird. I miss something.
EDIT: You mean...
double absolute(double number)
{
printf("%f ", number);
unsigned long long* x = (unsigned long long*)&number;
*x &= 0x7fffffff;
number = *(double *)x;
printf("%f \n",...
If you don't have a license of a Windows 64bit copy you can try for free a Linux distro.
So, the moral of this story is that there is no way to apply a mask on an double. Right?
I tried to cast it and then use a mask but it doesn't work because some digits are truncated.
But as you can see, I don't use the elements of the array after in the program. I merely write in the array after the results, so I don't care what were its previous values.
What I am really...
Indeed. It seems like you are using one extra unnecessary loop.
for (k = 0; diff > epsilon && k <= 1000; k++)
{
diff = 0;
// for each line in the array
for (i = 1; i < n - 1; i++)
{
// for each column in the...
yes.
If you don't like 19, you can try 31, 63 etc which are Mersenne Primes.
...To be on topic, programming needs maths if you want to understand some underlying concepts. But if you are not really...
Where can I find what exactly does?
The best that I have found till now is:
inline float
fabs(float __x)
{ return __builtin_fabsf(__x); }
inline long double
fabs(long double __x)...