Raised This Month: $ Target: $400
 0% 

Quicksort and copy


Post New Thread Reply   
 
Thread Tools Display Modes
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
Old 08-29-2012, 14:59
Liverwiz
This message has been deleted by Liverwiz. Reason: nvmd
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 08-29-2012 , 17:33   Re: Quicksort and copy
Reply With Quote #2

Dynamic arrays have their own sorting natives, so create a temp array, copy the default aray in it, use the sort native in the temp array.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 08-29-2012 , 18:22   Re: Quicksort and copy
Reply With Quote #3

That's what i ended up doing in the mean time till i figured this out.

I wanted to skip the first iteration of creating a temp array by sorting directly into the temp.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Old 08-30-2012, 03:29
maximac
This message has been deleted by asherkin. Reason: Spam.
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-30-2012 , 03:31   Re: Quicksort and copy
Reply With Quote #4

Quote:
Originally Posted by maximac View Post
FUNCTION CALLS My implementation avoids function calls. Calling (and returning from) a function is time-consuming, and not because the content of the function takes time to execute — just getting into the function, and back out of it, uses processor time.
Is it just me or are the bots getting more and more retarded?
Backstabnoob is offline
Reply



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