-Under construction -

 

 
'== ~ 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 (1st dimension value) == '== loBound and hiBound are simply the upper and lower == '== bounds of the array's "row" dimension. It's probably == '== easiest to use the LBound and UBound functions to == '== set these. == '== SortDir - ASC, ascending; DESC, Descending == '==--------------------------------------------------------== if not (hiBound - loBound = 0) then Dim pivot(),loSwap,hiSwap,temp,counter Redim pivot (Ubound(vec,2)) SortDir = UCase(SortDir) '== Two items to sort if hiBound - loBound = 1 then if (SortDir = "ASC") then if FormatCompare(vec(loBound,SortField),vec(hiBound,SortField)) > FormatCompare(vec(hiBound,SortField),vec(loBound,SortField)) then Call SwapRows(vec,hiBound,loBound) else if FormatCompare(vec(loBound,SortField),vec(hiBound,SortField)) < FormatCompare(vec(hiBound,SortField),vec(loBound,SortField)) then Call SwapRows(vec,hiBound,loBound) end if End If '== Three or more items to sort For counter = 0 to Ubound(vec,2) pivot(counter) = vec(int((loBound + hiBound) / 2),counter) vec(int((loBound + hiBound) / 2),counter) = vec(loBound,counter) vec(loBound,counter) = pivot(counter) Next loSwap = loBound + 1 hiSwap = hiBound do '== Find the right loSwap if (SortDir = "ASC") then while loSwap < hiSwap and FormatCompare(vec(loSwap,SortField),pivot(SortField)) <= FormatCompare(pivot(SortField),vec(loSwap,SortField)) loSwap = loSwap + 1 wend else while loSwap < hiSwap and FormatCompare(vec(loSwap,SortField),pivot(SortField)) >= FormatCompare(pivot(SortField),vec(loSwap,SortField)) loSwap = loSwap + 1 wend end if '== Find the right hiSwap if (SortDir = "ASC") then while FormatCompare(vec(hiSwap,SortField),pivot(SortField)) > FormatCompare(pivot(SortField),vec(hiSwap,SortField)) hiSwap = hiSwap - 1 wend else while FormatCompare(vec(hiSwap,SortField),pivot(SortField)) < FormatCompare(pivot(SortField),vec(hiSwap,SortField)) hiSwap = hiSwap - 1 wend end if '== Swap values if loSwap is less then hiSwap if loSwap < hiSwap then Call SwapRows(vec,loSwap,hiSwap) loop while loSwap < hiSwap For counter = 0 to Ubound(vec,2) vec(loBound,counter) = vec(hiSwap,counter) vec(hiSwap,counter) = pivot(counter) Next '== Recursively call function .. the beauty of Quicksort '== 2 or more items in first section if loBound < (hiSwap - 1) then Call QuickSort(vec,loBound,hiSwap-1,SortField,SortDir) '== 2 or more items in second section if hiSwap + 1 < hibound then Call QuickSort(vec,hiSwap+1,hiBound,SortField,SortDir) end if End Sub 'QuickSort 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 End Sub 'SwapRows function FormatCompare(sOne,sTwo) '==------------------------------------------== '== Checks sOne & sTwo, returns sOne as a == '== Numeric if both pass isNumeric, if not == '== returns sOne as a string. == '==------------------------------------------== if (isNumeric(Trim(sOne)) AND isNumeric(Trim(sTwo))) then FormatCompare = CDbl(Trim(sOne)) else FormatCompare = Trim(sOne) end if end function dim fs,fo,file set fs=Server.CreateObject("Scripting.FileSystemObject") path=Request.ServerVariables("APPL_PHYSICAL_PATH") & "Login\" set fo=fs.GetFolder(path) Dim files() redim files(fo.files.count,3) i=0 for each file in fo.files extension = lcase(fs.GetExtensionName(file.name)) if extension="rar" or extension="zip" or extension="gz" then files(i,1)=mid(file.Name,6,8) files(i,2)=file.Name files(i,3)=extension i=i+1 end if next Call QuickSort(files,0,ubound(files,1),1,"DESC") actualVal="" i=1 do while i < ubound(files,1)+1 if files(i,1)<>"" then actualVal=files(i,1) if files(i-1,1)=actualVal and files(i,3)="xml" then Call SwapRows(files,i-1,i) end if end if i=i+1 loop i=0 do while i < ubound(files,1)+1 if files(i,1)<>"" then Response.write("" & vbcr) Response.write("" & vbcr) Response.write("" & vbcr) Response.write("" & files(i,2) & "
" & vbcr) Response.write("
" & vbcr) Response.write("" & vbcr) Response.write("" & vbcr) Response.write("" & vbcr) Response.write(" " & mid(files(i,1),7,2) & "/" & mid(files(i,1),5,2) & "/" & mid(files(i,1),1,4) & " " & vbcr) Response.write("" & vbcr) Response.write("" & vbcr) Response.write("" & vbcr) end if i=i+1 loop set fo=nothing set fs=nothing %>