Help me with using pointer in my Quicksort Program

#include
#define maxsize 10

void quicksort (int a, int b);
//void mergesort ();

int i, j, k;
float ES26[maxsize];
float *ptr, sum, median, mode;

int main ()
{
int x=1;
printf("Input at most 10 floating point numbers, each entry followed by ENTER.
Input 0 if you want to stop:
");
for (i=1, j=1; j==1 || i==10; i++)
{
printf("%d) ", i);
scanf("%f", &ES26[i]);
ptr=&ES26[i];

if (*ptr==0)
{
x=i-1;
j=2;
}
if (i==10)
{
x=i;
j=2;
}
}

if (x==2 || x==4 || x==6 || x==8 || x==10)
{
printf("
You entered %i valid entries.", x);
ptr = &ES26[i];
quicksort(0, x);

printf("
Supposed to Quicksort.");
}

if (x==1 || x==3 || x==5 || x==7 || x==9)
{
printf("
You entered %i valid entries.", x);
//meregesort

printf("
Supposed to Mergesort.");
}

//ptr = &ES26[i];

for (i=1; i<=x; i++) //for printing
{
ptr=&ES26[i];
printf("
Entry %i is %f", i, *ptr);
sum = sum + *ptr;
}
printf("
The mean is %f", sum/x);



getchar();
getchar();
getchar();
getchar();
}

void quicksort(int a, int b)
{
int rtidx=0, ltidx=0, k=a, l=0;
float leftarr[maxsize], rtarr[maxsize];
float pivot=ES26[a];

if(a==b)return;

while(k<b) {
++k;
if(ES26[k] < ES26[a])
{
leftarr[ltidx]=ES26[k];
ltidx++;
}
else {
rtarr[rtidx]=ES26[k];
rtidx++;
}
}
k=a;

for(l=0; l<ltidx; ++l)
ES26[k++] = leftarr[l];
ES26[k++] = pivot;

for(l=0; l<rtidx; ++l)
ES26[k++] = rtarr[l];

if(ltidx>0)
quicksort(a, a+ltidx-1);
if(rtidx>0)
quicksort(b-rtidx+1, b);
}

void printarr(int a)
{
int i;
for(i=0;i<a;i++)
{
printf("%d",ES26[i]);
printf("
");
}
}


PROBLEM:

Instead of using the array notation in the void quicksort(int a, int b) subfunction, to access the array elements via the pointer *ptr
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories