日期:2011-10-26  浏览次数:20864 次

 

<%

DimaData
aData=Array(3,2,4,1,6,0)

CallResponseArray(aData,"原来顺序")
CallResponseArray(SelectSort(aData),"选择排序")
CallResponseArray(QuickSort(aData),"快速排序")
CallResponseArray(InsertSort(aData),"插入排序")
CallResponseArray(BubbleSort(aData),"冒泡排序")


'选择排序
FunctionSelectSort(a_Data)
   Dimi,j,k
   Dimbound,t
   bound=UBound(a_Data)

   Fori=0Tobound-1
       k=i
       Forj=i+1Tobound
           Ifa_Data(k)>a_Data(j)Then
               k=j
           EndIf
       Next
       t=a_Data(i)
       a_Data(i)=a_Data(k)
       a_Data(k)=t
   Next

   SelectSort=a_Data
EndFunction


'快速排序
FunctionQuickSort(a_Data)
   Dimi,j
   Dimbound,t
   bound=UBound(a_Data)

   Fori=0Tobound-1
       Forj=i+1Tobound
           Ifa_Data(i)>a_Data(j)Then
               t=a_Data(i)
               a_Data(i)=a_Data(j)
               a_Data(j)=t
           EndIf
       Next
   Next

   QuickSort=a_Data
EndFunction


'冒泡排序
FunctionBubbleSort(a_Data)
   Dimbound
   bound=UBound(a_Data)
   DimbSorted,i,t
   bSorted=False
   
   DoWhilebound>0AndbSorted=False
       
       bSorted=True
       Fori=0Tobound-1
           Ifa_Data(i)>a_Data(i+1)Then
               t=a_Data(i)
               a_Data(i)=a_Data(i+1)
               a_Data(i+1)=t
               bSorted=False
           EndIf
       Next
       bound=bound-1
   Loop
   
   BubbleSort=a_Data
EndFunction


'插入排序
FunctionInsertSort(a_Data)
   Dimbound
   bound=UBound(a_Data)
   Dimi,j,t

   Fori=1Tobound
       t=a_Data(i)
       j=i
       DoWhilet<a_Data(j-1)Andj>0
           a_Data(j)=a_Data(j-1)
           j=j-1