HCAAdmin
asked on
How/What do I change the Quicksort function (execerpt below) to sort in descending order (Z to A; n to 0)?
I'm having a problem trying to do a reverse sort (descending order; Z to A; n to 0).
The Quicksort function (mentioned below) does a sort in ascending order (A to Z; 0 to n) and is an excerpt from a C++ book called "Data Abstractions & Structures using C++". I've used the following code to do a sort of filenames/folders in a customized Enhanced Browser Page for IIS 5.0 and WORKS!!! I've tried to manipulate variables within the function to do a reverse sort however I've had no luck....
My question: How/What do I change the Quicksort function (execerpt below) to sort in descending order (Z to A; n to 0)?
'_________________________ __________ __________ __________ __________ __
Sub QuickSort(vec,loBound,hiBo und,SortFi eld)
'==----------------------- ---------- ---------- ---------- ---==
'== Sort a 2 dimensional array on SortField ==
'== ==
'== This procedure is adapted from the algorithm given in: ==
'== ~ Data Abstractions & Structures using C++ by ~ ==
'== ~ Mark Headington and David Riley, pg. 586 ~ ==
'== Quicksort is the fastest array sorting routine For ==
'== unordered arrays. Its big O is n log n ==
'== ==
'== Parameters: ==
'== vec - array to be sorted ==
'== SortField - The field to sort on (2nd dimension value) ==
'== loBound and hiBound are simply the upper and lower ==
'== bounds of the array's 1st dimension. It's probably ==
'== easiest to use the LBound and UBound functions to ==
'== Set these. ==
'==----------------------- ---------- ---------- ---------- ---==
Dim pivot(),loSwap,hiSwap,temp ,counter
Redim pivot (Ubound(vec,2))
'== Two items to sort
if hiBound - loBound = 1 then
if vec(loBound,SortField) > vec(hiBound,SortField) then
Call SwapRows(vec,hiBound,loBou nd)
End If
End If
The Quicksort function (mentioned below) does a sort in ascending order (A to Z; 0 to n) and is an excerpt from a C++ book called "Data Abstractions & Structures using C++". I've used the following code to do a sort of filenames/folders in a customized Enhanced Browser Page for IIS 5.0 and WORKS!!! I've tried to manipulate variables within the function to do a reverse sort however I've had no luck....
My question: How/What do I change the Quicksort function (execerpt below) to sort in descending order (Z to A; n to 0)?
'_________________________
Sub QuickSort(vec,loBound,hiBo
'==-----------------------
'== Sort a 2 dimensional array on SortField ==
'== ==
'== This procedure is adapted from the algorithm given in: ==
'== ~ Data Abstractions & Structures using C++ by ~ ==
'== ~ Mark Headington and David Riley, pg. 586 ~ ==
'== Quicksort is the fastest array sorting routine For ==
'== unordered arrays. Its big O is n log n ==
'== ==
'== Parameters: ==
'== vec - array to be sorted ==
'== SortField - The field to sort on (2nd dimension value) ==
'== loBound and hiBound are simply the upper and lower ==
'== bounds of the array's 1st dimension. It's probably ==
'== easiest to use the LBound and UBound functions to ==
'== Set these. ==
'==-----------------------
Dim pivot(),loSwap,hiSwap,temp
Redim pivot (Ubound(vec,2))
'== Two items to sort
if hiBound - loBound = 1 then
if vec(loBound,SortField) > vec(hiBound,SortField) then
Call SwapRows(vec,hiBound,loBou
End If
End If
if vec(loBound,SortField) < vec(hiBound,SortField) then
ASKER
Thanks for the reply....
However it still doesn't seem to work. Perhaps I need to change something in the subroutine called "Swaprows"?
The following is the subroutine called within the Quicksort() function:
Parameters being passed into the subroutine:
SwapRows(vec,hiBound,loBou nd)
-------------------------- ---------- ---------- ---------- -----
Sub SwapRows(ary,row1,row2)
'== This proc swaps two rows of an array
Dim x,tempvar
For x = 0 to Ubound(ary,2)
tempvar = ary(row1,x)
ary(row1,x) = ary(row2,x)
ary(row2,x) = tempvar
Next
However it still doesn't seem to work. Perhaps I need to change something in the subroutine called "Swaprows"?
The following is the subroutine called within the Quicksort() function:
Parameters being passed into the subroutine:
SwapRows(vec,hiBound,loBou
--------------------------
Sub SwapRows(ary,row1,row2)
'== This proc swaps two rows of an array
Dim x,tempvar
For x = 0 to Ubound(ary,2)
tempvar = ary(row1,x)
ary(row1,x) = ary(row2,x)
ary(row2,x) = tempvar
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I got an answer to this question....
Check out the response to my post! https://www.experts-exchange.com/questions/22039210/How-to-do-a-reverse-sort-descending-of-filenames-using-Quicksort-function.html
Thanks for the effort and I will offer some points! :)
Check out the response to my post! https://www.experts-exchange.com/questions/22039210/How-to-do-a-reverse-sort-descending-of-filenames-using-Quicksort-function.html
Thanks for the effort and I will offer some points! :)