### quick sorting a dynamic array

no one seems to want to talk about how to work with variable length arrays so im having trouble figuring it out.

i used this code to generate the arrays. the "Dice" values are in the several thousands.
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````int* humFight(int humDice) { int* a1=new int[humDice]; int rolled=0; srand (time(NULL)); while(rolleda1[j]) { int temp=a1[i]; a1[i]=a1[j]; a1[j]=temp; } } } return a1; } int* posFight(int posDice) { int* a2=new int[posDice]; int rolled=0; srand (time(NULL)); while(rolleda2[j]) { int temp=a2[i]; a2[i]=a2[j]; a2[j]=temp; } } } return a2; }``````

i used this algorithm to make the arrays the same length with 0s at the end

 ``123456789101112131415`` `````` if (sizeof(a1)>sizeof(a2)) { for(int i=sizeof(a2)+1;isizeof(a1)) { for(int i=sizeof(a1)+1;i

and this is the base quicksort that is built for fixed length arrays

 ``1234567891011121314151617181920212223242526272829`` ``````void quickSort(int arr[], int left, int right) { int i = left, j = right; int tmp; int pivot = arr[(left + right) / 2]; /* partition */ while (i <= j) { while (arr[i] < pivot) i++; while (arr[j] > pivot) j--; if (i <= j) { tmp = arr[i]; arr[i] = arr[j]; arr[j] = tmp; i++; j--; } }; /* recursion */ if (left < j) quickSort(arr, left, j); if (i < right) quickSort(arr, i, right); }``````

if you guys know how to convert the quicksort so it will accept my arrays that would be great. thanks.
Wait, what are you sorting here? If it's numerical, I know that there's a function in the algorithm library that does it for you... Also, in the case of dynamic arrays, you already know the values of humDice and posDice, since they have to be sent specifically to those functions to create arrays... can't you just pass their values over to quickSort as well?
Topic archived. No new replies allowed.