常用的幾種asp排序方法介紹

來源:互聯網
上載者:User
排序  

<%

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
       Loop
       a_Data(j)=t
   Next
       
   InsertSort=a_Data
EndFunction

'輸出數組
SubResponseArray(a_Data,str)
   Dims
   s=""
   Response.Write"<b>"&str&":</b>"
   Fori=0ToUBound(a_Data)
       s=s&a_Data(i)&","
   Next
   s=Left(s,Len(s)-1)
   Response.Writes
   Response.Write"<hr>"
EndSub

%>



相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。