- Joined
- Oct 24, 2012
- Messages
- 6,545
Hello i have a quicksort algorithm that works good but it needs to work with any size of integer array. I don't know how to do that. Right now it sorts from high to low.
Any help is appreciated.
JASS ONLY PLEASE.
Any help is appreciated.
JASS ONLY PLEASE.
JASS:
function H2LPartitionFunc takes integer left, integer right, integer pivot returns integer
local integer temp1
call BJDebugMsg( "left = " + I2S( left))
call BJDebugMsg( "right = " + I2S( right))
call BJDebugMsg( "pivot = " + I2S( pivot))
call DisplayTextToPlayer( Player(0), 0, 0, " ")
loop
exitwhen left == right
loop
exitwhen udg_h2LGlobalInt2[ left] < udg_h2LGlobalInt2[ pivot] or left == pivot
call BJDebugMsg( "left < pivot = " + I2S( udg_h2LGlobalInt2[ left]) + " < " + I2S( udg_h2LGlobalInt2[ pivot]))
set left = left + 1
endloop
loop
exitwhen udg_h2LGlobalInt2[ right] > udg_h2LGlobalInt2[ pivot] or right == pivot
call BJDebugMsg( "right > pivot = " + I2S( udg_h2LGlobalInt2[ right]) + " > " + I2S( udg_h2LGlobalInt2[ pivot]))
set right = right - 1
endloop
call BJDebugMsg( "left = " + I2S( left))
call BJDebugMsg( "right = " + I2S( right))
call BJDebugMsg( "pivot = " + I2S( pivot))
call DisplayTextToPlayer( Player(0), 0, 0, " ")
set temp1 = udg_h2LGlobalInt2[ left]
set udg_h2LGlobalInt2[ left] = udg_h2LGlobalInt2[ right]
set udg_h2LGlobalInt2[ right] = temp1
if left == pivot then
set pivot = right
elseif right == pivot then
set pivot = left
endif
endloop
return pivot
endfunction
function H2LSortFunc1 takes nothing returns nothing
//it is easier to read with locals
local integer left = 1 // udg_h2LMinValue
local integer right = 9 // udg_h2LMaxValue
local integer pivot
local integer pivot2
local integer temp2
local integer L = left
local integer L1 = 1
set udg_h2LGlobalInt2[ 1] = 24
set udg_h2LGlobalInt2[ 2] = 2
set udg_h2LGlobalInt2[ 3] = 5
set udg_h2LGlobalInt2[ 4] = 21
set udg_h2LGlobalInt2[ 5] = 19
set udg_h2LGlobalInt2[ 6] = 42
set udg_h2LGlobalInt2[ 7] = 17
set udg_h2LGlobalInt2[ 8] = 35
set udg_h2LGlobalInt2[ 9] = 31
loop
exitwhen L1 > 9
call DisplayTextToPlayer( Player(0), 0, 0, I2S( udg_h2LGlobalInt2[ L1]))
set L1 = L1 + 1
endloop
call DisplayTextToPlayer( Player(0), 0, 0, " ")
//loop
//exitwhen right < left
set pivot = ( right - left) / 2
set pivot = H2LPartitionFunc( left, right, pivot)
call H2LPartitionFunc( left, pivot, ( pivot + left) / 2)
call H2LPartitionFunc( pivot, right, ( right + pivot) / 2)
call BJDebugMsg( "r pivot = " + I2S( pivot))
//endloop
call DisplayTextToPlayer( Player(0), 0, 0, " ")
set L1 = 1
loop
exitwhen L1 > 9
call DisplayTextToPlayer( Player(0), 0, 0, I2S( udg_h2LGlobalInt2[ L1]))
set L1 = L1 + 1
endloop
endfunction