How/What do I change the Quicksort function (execerpt below) to sort in descending order (Z to A; n to 0)?

Posted on 2006-10-26
Medium Priority
Last Modified: 2010-04-01
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
Question by:HCAAdmin
  • 2
  • 2
LVL 19

Expert Comment

ID: 17815844
if vec(loBound,SortField) < vec(hiBound,SortField) then

Author Comment

ID: 17821843
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:
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
LVL 19

Accepted Solution

BrianGEFF719 earned 750 total points
ID: 17824482
Can you post full code please.

Author Comment

ID: 17833634
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! :)

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

809 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