| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
sortng
i try to sort an array inside a function passed by reference..
when i try to do this the compiler give me errr that i try to change read only memory. how can i sort array passed by reference? |
|
#2
|
|||
|
|||
|
You will probably need to post your code as well to put the problem in context, this is not something I've encountered before.
-KM- |
|
#3
|
|||
|
|||
|
sortng
try quick sort... just call quickSort in your application...
source code below... void quickSort(int numbers[], int array_size) { q_sort(numbers, 0, array_size - 1); } void q_sort(int numbers[], int left, int right) { int pivot, l_hold, r_hold; l_hold = left; r_hold = right; pivot = numbers[left]; while (left < right) { while ((numbers[right] >= pivot) && (left < right)) right--; if (left != right) { numbers[left] = numbers[right]; left++; } while ((numbers[left] <= pivot) && (left < right)) left++; if (left != right) { numbers[right] = numbers[left]; right--; } } numbers[left] = pivot; pivot = left; left = l_hold; right = r_hold; if (left < pivot) q_sort(numbers, left, pivot-1); if (right > pivot) q_sort(numbers, pivot+1, right); } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > sortng |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|