Raised This Month: $ Target: $400
 0% 

Quicksort and copy


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-29-2012 , 14:33   Quicksort and copy
Reply With Quote #1

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:inputleftright ,Array:output)
{
    new 
cell[PowersCell], tmpCell[PowersCell]
    new 
leftright
    
new pivot
    
    ArrayGetArray
(input, (j) / 2cell)
    
pivot cell[LEVEL]
    
        
// partition inupt
    
while(<= j)
    {
        
ArrayGetArray(inputicell)
        while(
cell[LEVEL] < pivot)
            
ArrayGetArray(input, ++icell)
            
        
ArrayGetArray(inputjcell)
        while(
cell[LEVEL] > pivot)
            
ArrayGetArray(input, --jcell)
            
        if(
<= j)
        {
            
ArrayGetArray(inputicell)
            clone(
celltmpCellPowersCell)
            
ArrayGetArray(inputjcell)
                
// input[i] = input[j]
            
ArraySetArray(outputicell)
            
ArraySetArray(outputjtmpCell)
            
i++
            
j++
        }
    }
    
    if(
left j)
        
quickSort(inputleftj)
    if(
right)
        
quickSort(inputiright)
}
clone(
inputoutputsize)
{
    for(new 
0sizei++)
        
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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:43.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode