0

hi, I have a problem with implementation of a quicksort algorithm. I have pseudo-code which helping me understand this, but I still can't make this program to work. Does anybody can help me figur out what is wrong in my code?

Thanks

My code :

```
#include <iostream>
#include <ctime>
void setA (int A[], int size)
{
for (int i=0; i< size; i++)
{
A[i] = rand()%10 + 1;
std::cout << i + 1 << " index value = " << A[i] << std::endl;
}
}
void printA (int A[], int size)
{
for (int i=0; i<size; i++)
{
std::cout << "now the value of index " << i + 1 << " = " << A[i] << std::endl;
}
}
int partition (int A[], int down, int top)
{
int w = A[down];
int i = down;
int j = top + 1;
do
{
j--;
} while (A[j] <= w);
do
{
i++;
} while (A[i] >= w);
if (i < j)
{
int temp = A[i];
A[i] = A[j];
A[j] = temp;
}
else
{
int temp = A[j];
A[j] = A[down];
A[down] = temp;
return j;
}
}
void quicksort (int A[], int down, int top)
{
if (down < top)
{
int j = partition (A, down, top);
quicksort (A, down, j-1);
quicksort (A, j+1, top);
}
}
int main()
{
srand((unsigned int)time(NULL));
int size;
std::cout << "Enter array size : " << std::endl;
std::cin >> size;
int A[10000];
int down = 0;
int top = size;
setA (A, size);
std::cout << "--------------------------------------------" << std::endl;
partition(A, down, top);
printA (A, size);
system("pause");
return 0;
}
```

I'm totaly beginner so if my code is ugly or non-standard than correct me pls.

*Edited 6 Years Ago by gfx*: n/a