#include<stdio.h>
#include <time.h>
#include <stdlib.h>
int w, q, p, r;
int tab[100];
void main ()
{
int i;
srand(time(0));
for (i = 0; i < 100; i += 1)
{
tab[i]=rand()%100;
}
display(tab);
r = 37;
quicksnort(tab, 0, r-1);
display(tab);
}
int display (int tab[])
{
int i;
printf("
Your numbers :
");
for (i = 0; i < 100; i += 1)
{
printf(" %d", tab[i]);
}
}
int quicksnort(int tab[], int m, int n)
{
if (p<r)
{
q = partition(tab, m, n);
quicksnort(tab, m, q-1);
quicksnort(tab, q+1, n);
}
}
int partition(int tab[], int p, int r)
{
int x, i, j, part;
x = tab[p];
i = p-1;
j = r+1;
do
{
do
{
j = j-1;
} while (tab[j]<=x && j>=0);
do
{
i = i+1;
} while (tab[i]>=x && i<=0);
if (i<j)
{
part = tab[i];
tab[i]=tab[j];
tab[j]=part;
}
else
{
return j;
}
} while (1);
}
Hi, i have problem with the code above. It will compile but when i run it, it stops and display some sort of alert of "core dump". It s based on hoare version of quicksort, to be axact on that peudocode http://screenshooter.net/5359896/jyuogoj I ve tried everything to make it work, i think that it might have something to do with pointers. I think that because i m not sure how they work in C.
(OK,我知道他们指的是细胞之类的东西, 但我迷路了, 指针指针, 或用于函数的指针, 或用于函数的指针, 或用于函数的指针表, 以及类似的东西。 我真的不知道该从何处寻找更具体的信息 )
但也许解决办法比这简单些。