Asp classic 在经典ASP中对时间数组进行排序
我不得不回到我在经典ASP中构建的一个旧应用程序,并做了一些更改,但有一点让我感到困惑 我有一个字符串,例如:Asp classic 在经典ASP中对时间数组进行排序,asp-classic,Asp Classic,我不得不回到我在经典ASP中构建的一个旧应用程序,并做了一些更改,但有一点让我感到困惑 我有一个字符串,例如: theTimings = "12:00-14:30,18:00-22:30,07:30-10:30" 我正在使用 timingsArray=Split(theTimings,",") 但是,我需要对该数组进行排序,以便最早的时间首先出现,即 07:30-10:30,12:00-14:30,18:00-22:30 有人知道怎么做吗?如果要对数组进行排序,经典VBScript
theTimings = "12:00-14:30,18:00-22:30,07:30-10:30"
我正在使用
timingsArray=Split(theTimings,",")
但是,我需要对该数组进行排序,以便最早的时间首先出现,即
07:30-10:30,12:00-14:30,18:00-22:30
有人知道怎么做吗?如果要对数组进行排序,经典VBScript ASP不提供该功能。因此,您有4个选项:,将数组转换为或“滚动您自己的算法”(也称为) 很抱歉,我不知道哪一个是最佳的或更快的,但如果您使用VBScript,我建议使用快速排序。下面是一个适用于我改编的字符串的实现:
Dim prt
prt=数组(“此”、“数组”、“有组织”、“是”、“不是”)
打印阵列(prt)
arr_排序prt
打印阵列(prt)
子arr_排序(arr)
调用快速排序(arr,0,ubound(arr,1))
端接头
副船首(ary,第1排,第2排)
暗温度
tempvar=ary(第1行)
ary(第1行)=ary(第2行)
ary(行2)=临时变量
末端接头“船头”
子快速排序(vec、LOBOND、HIBOND)
'==--------------------------------------------------------==
'==对一维数组进行排序==
'== ==
'==此过程根据以下中给出的算法进行调整:==
'==~(C++)使用~+==的数据抽象和结构
“=~马克·海丁顿和大卫·莱利,第586页~==
'==快速排序是最快的数组排序例程==
'==无序数组。它的大O是n对数n==
'== ==
'==参数:==
'==vec-要排序的数组==
'==loBound和hiBound只是上下两种==
'==数组第一维的边界。可能是==
'==最容易使用LBound和UBound函数==
'==设置这些==
'==--------------------------------------------------------==
暗轴、loSwap、hiSwap、温度、计数器
'==要排序的两个项目
如果HIBOND-LOBOND=1,则
如果vec(loBound)>vec(hiBound),则
呼叫SwapRows(vec、HIBOND、LOBOND)
如果结束
如果结束
'==要排序的三个或更多项目
pivot=vec(int((loBound+hiBound)/2))
vec(int((loBound+hiBound)/2))=vec(loBound)
vec(loBound)=枢轴
loSwap=loBound+1
hiSwap=hiBound
做
'==找到正确的位置
虽然loSwap
很抱歉,我不知道哪一个是最佳的或更快的,但如果您使用VBScript,我建议使用快速排序。下面是一个适用于我改编的字符串的实现:
Dim prt
prt=数组(“此”、“数组”、“有组织”、“是”、“不是”)
打印阵列(prt)
arr_排序prt
打印阵列(prt)
子arr_排序(arr)
调用快速排序(arr,0,ubound(arr,1))
端接头
副船首(ary,第1排,第2排)
暗温度
tempvar=ary(第1行)
ary(第1行)=ary(第2行)
ary(行2)=临时变量
末端接头“船头”
子快速排序(vec、LOBOND、HIBOND)
'==--------------------------------------------------------==
'==对一维数组进行排序==
'== ==
'==此过程根据以下中给出的算法进行调整:==
'==~(C++)使用~+==的数据抽象和结构
“=~马克·海丁顿和大卫·莱利,第586页~==
'==快速排序是最快的数组排序例程==
'==无序数组。它的大O是n对数n==
'== ==
'==参数:==
'==vec-要排序的数组==
'==loBound和hiBound只是上下两种==
'==数组第一维的边界。可能是==
'==最容易使用LBound和UBound函数==
'==设置这些==
'==--------------------------------------------------------==
暗轴、loSwap、hiSwap、温度、计数器
'==要排序的两个项目
如果HIBOND-LOBOND=1,则
如果vec(loBound)>vec(hiBound),则
呼叫SwapRows(vec、HIBOND、LOBOND)
如果结束
如果结束
'==要排序的三个或更多项目
pivot=vec(int((loBound+hiBound)/2))
vec(int((loBound+hiBound)/2))=vec(loBound)
vec(loBound)=枢轴
loSwap=loBound+1
hiSwap=hiBound
做
'==找到正确的位置
而loSwapDim prt
prt = Array("this", "array", "organized", "is", "not")
print_array(prt)
arr_sort prt
print_array(prt)
Sub arr_sort (arr)
Call QuickSort(arr, 0, ubound(arr, 1))
End Sub
Sub SwapRows (ary,row1,row2)
Dim tempvar
tempvar = ary(row1)
ary(row1) = ary(row2)
ary(row2) = tempvar
End Sub 'SwapRows
Sub QuickSort (vec,loBound,hiBound)
'==--------------------------------------------------------==
'== Sort a 1 dimensional array ==
'== ==
'== 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 ==
'== 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
'== Two items to sort
if hiBound - loBound = 1 then
if vec(loBound) > vec(hiBound) then
Call SwapRows(vec,hiBound,loBound)
End If
End If
'== Three or more items to sort
pivot = vec(int((loBound + hiBound) / 2))
vec(int((loBound + hiBound) / 2)) = vec(loBound)
vec(loBound) = pivot
loSwap = loBound + 1
hiSwap = hiBound
Do
'== Find the right loSwap
while loSwap < hiSwap and vec(loSwap) <= pivot
loSwap = loSwap + 1
wend
'== Find the right hiSwap
while vec(hiSwap) > pivot
hiSwap = hiSwap - 1
wend
'== Swap values if loSwap is less then hiSwap
if loSwap < hiSwap then Call SwapRows(vec,loSwap,hiSwap)
Loop While loSwap < hiSwap
vec(loBound) = vec(hiSwap)
vec(hiSwap) = pivot
'== 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)
'== 2 or more items in second section
if hiSwap + 1 < hibound then Call QuickSort(vec,hiSwap+1,hiBound)
End Sub 'QuickSort
public sub print_array (var)
call print_r_depth(var, 0)
end sub
public sub print_r_depth (var, depth)
if depth=0 then
response.write("<pre>" & Tab(depth))
response.write(typename(var))
end if
if isarray(var) then
response.write(Tab(depth) & " (<br />")
dim x
for x=0 to uBound(var)
response.write(Tab(depth+1) & "("&x&")")
call print_r_depth(var(x), depth+2)
response.write("<br />")
next
response.write(Tab(depth) & ")")
end if
select case vartype(var)
case VBEmpty: 'Uninitialized
case VBNull: 'Contains no valid data
case VBDataObject: 'Data access object
case VBError:
case VBArray:
case VBObject:
case VBVariant:
case else:
if vartype(var) < 16 then
response.write(" => " & var)
else
response.write(" - vartype:" & vartype(var) & " depth:" & depth)
end if
end select
if depth=0 then response.write("</pre>") end if
end sub
public function Tab (spaces)
dim val, x
val = ""
for x=1 to spaces
val=val & " "
next
Tab = val
end function