Solved

How to do a reverse sort (descending) of filenames using Quicksort function?

Posted on 2006-10-26
4
1,223 Views
Last Modified: 2011-10-03
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,hiBound,SortField)
  '==--------------------------------------------------------==
  '== 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,loBound)
    End If
  End If
0
Comment
Question by:HCAAdmin
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17816036
if vec(loBound,SortField) < vec(hiBound,SortField) then
0
 

Author Comment

by:HCAAdmin
ID: 17821841
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,loBound)
-------------------------------------------------------------
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
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
ID: 17822057
try this change:

  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,loBound,hiBound)
    End If
  End If

AW
0
 

Author Comment

by:HCAAdmin
ID: 17833631
I got an answer to this question....

Check out the response to my post! http://www.experts-exchange.com/Web/Q_22039210.html

Thanks for the effort and I will offer some points! :)
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mydac connection data base issue 3 107
if loop in java 3 114
Choosing the right language for new project 8 58
word0 challenge 3 58
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now