Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scriptname TestSorts Hidden
- function StartSortFunctionInt()
- Int[] aIntArray = New Int[13]
- aIntArray[0] = 10
- aIntArray[1] = 11
- aIntArray[2] = -1
- aIntArray[3] = 0
- aIntArray[4] = 8
- aIntArray[5] = 1
- aIntArray[6] = 50
- aIntArray[7] = 8
- aIntArray[8] = 50
- aIntArray[9] = 10
- aIntArray[10] = 0
- aIntArray[11] = 44
- aIntArray[12] = 999
- Debug.Trace("aIntArray as String Before: " + aIntArray as String)
- cArrayQuickSortInt(aIntArray) ; works just fine
- Debug.Trace("aIntArray as String After: " + aIntArray as String)
- endfunction
- ; works great
- function cArrayQuickSortInt(Int[] aArray, Int low = -1, Int high = -1) global
- if high == -1
- high = aArray.length - 1
- endif
- if low == -1
- low = 0
- endif
- if low < high
- ; pi is partitioning index, after this aArray[pivot] now at right place
- Int pi = cArrayPartitionInt(aArray, low, high)
- ; Separately sort elements before partition and after partition
- cArrayQuickSortInt(aArray, low, pi - 1)
- cArrayQuickSortInt(aArray, pi + 1, high)
- endif
- endfunction
- Int function cArrayPartitionInt(Int[] aArray, Int low, Int high) global
- Int pivot = aArray[high]
- Int i = low - 1 ; Index of smaller element and indicates the right position of pivot found so far
- Int j = low
- while j <= (high - 1)
- if aArray[j] < pivot
- i += 1
- aArraySwapIndexInt(aArray, i, j)
- endif
- j += 1
- endwhile
- aArraySwapIndexInt(aArray, i + 1, high)
- return (i + 1)
- endfunction
- function StartSortFunctionString()
- String[] cArray = New String[14]
- cArray[0] = ""
- cArray[1] = "ppp"
- cArray[2] = ""
- cArray[3] = "rrr"
- cArray[4] = ""
- cArray[5] = "qqq"
- cArray[6] = ""
- cArray[7] = "ttt"
- cArray[8] = ""
- cArray[9] = "aaa"
- cArray[10] = ""
- cArray[11] = "bcb"
- cArray[12] = "bcb"
- cArray[13] = "zzz"
- Debug.Trace("cArray as String Before: " + cArray as String)
- cArrayQuickSortString(cArray) ; never makes it past here
- Debug.Trace("cArray as String After: " + cArray as String)
- endfunction
- ; doesn't work!
- function cArrayQuickSortString(String[] aArray, Int low = -1, Int high = -1) global
- if high == -1
- high = aArray.length - 1
- endif
- if low == -1
- low = 0
- endif
- if low < high
- ; pi is partitioning index, after this aArray[pivot] now at right place
- Int pi = cArrayPartitionString(aArray, low, high)
- ; Separately sort elements before partition and after partition
- cArrayQuickSortString(aArray, low, pi - 1)
- cArrayQuickSortString(aArray, pi + 1, high)
- endif
- endfunction
- Int function cArrayPartitionString(String[] aArray, Int low, Int high) global
- String pivot = aArray[high]
- Int i = low - 1 ; Index of smaller element and indicates the right position of pivot found so far
- Int j = low
- while j <= (high - 1)
- if aArray[j] < pivot
- i += 1
- aArraySwapIndexString(aArray, i, j)
- endif
- j += 1
- endwhile
- aArraySwapIndexString(aArray, i + 1, high)
- return (i + 1)
- endfunction
- function aArraySwapIndexInt(Int[] aArray, Int index1, Int index2) global
- Int tempValue = aArray[index1]
- aArray[index1] = aArray[index2]
- aArray[index2] = tempValue
- endfunction
- function aArraySwapIndexString(String[] aArray, Int index1, Int index2) global
- String tempValue = aArray[index1]
- aArray[index1] = aArray[index2]
- aArray[index2] = tempValue
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment