一个 C# 版的冒泡排序法

从小到大排序

int [] myArray = new int [] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
// 取长度最长的词组 -- 冒泡法
for ( int j=1;j

 1<myarray.length;j (="" )="" ++="" ++)="" -="" 1;i="" for="" i="0;i&lt;myArray.Length" int="" myarray[i]="" {="" 如果=""> myArray[i+1] ,则 myArray[i] 上浮一位   
 2if  ( myArray[i]&gt;myArray[i+1])   
 3{   
 4int  temp = myArray[i];   
 5myArray[i] = myArray[i+1];   
 6myArray[i+1] = temp;   
 7}   
 8}   
 9}   
10  
11**从大到小排序  
12  
13** int  [] myArray =  new  int  [] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };   
14// 取长度最长的词组 -- 冒泡法   
15for  (  int  j=1;j&lt;myArray.Length;j ++ )   
16{   
17for  (int i=0;i&lt;myArray.Length - 1;i ++)   
18{   
19// 如果 myArray[i] &lt; myArray[i+1] ,则 myArray[i] 下沉一位   
20if  ( myArray[i]&lt;myArray[i+1])   
21{   
22int  temp = myArray[i];   
23myArray[i] = myArray[i+1];   
24myArray[i+1] = temp;   
25}   
26}   
27}</myarray.length;j>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus