I'm trying to sort a dynamic array into a temporary dynamic array. So i can then print the sorted one without messing up the original array.
Because amxmodx uses quicksort (which is the best way) I'm also using quicksort. Now....i have as far as putting all the changed cells into the array, but the ones that don't move i'm just having a brain fart as to how i can tell if they've been moved or not. Can someone hint me towards how to tell?
This is the code that i have.
PHP Code:
quickSort(Array:input, left, right ,Array:output)
{
new cell[PowersCell], tmpCell[PowersCell]
new i = left, j = right
new pivot
ArrayGetArray(input, (i + j) / 2, cell)
pivot = cell[LEVEL]
// partition inupt
while(i <= j)
{
ArrayGetArray(input, i, cell)
while(cell[LEVEL] < pivot)
ArrayGetArray(input, ++i, cell)
ArrayGetArray(input, j, cell)
while(cell[LEVEL] > pivot)
ArrayGetArray(input, --j, cell)
if(i <= j)
{
ArrayGetArray(input, i, cell)
clone(cell, tmpCell, PowersCell)
ArrayGetArray(input, j, cell)
// input[i] = input[j]
ArraySetArray(output, i, cell)
ArraySetArray(output, j, tmpCell)
i++
j++
}
}
if(left < j)
quickSort(input, left, j)
if(i < right)
quickSort(input, i, right)
}
clone(input, output, size)
{
for(new i = 0; i < size; i++)
output[i] = input[i]
}
clone is just a pretty way of copying an array into another.
Also...if i got anything wrong, please let me know.
__________________