ruby
?
#冒泡排序 def bulle_sort a = [40,12,23,543,53,2,77,34] i =0 while (i<a.length) j=i+1 while(j<a.length) if a[i]>a[j] temp = a[j] a[j] = a[i] a[i] = temp end j=j+1 end i=i+1 end end
?java
?
public static void main(String[] args) { int [] a = {40,12,23,543,53,2,77,34}; int temp = 0; for(int i =0;i<a.length;i++){ for(int j=i+1;j<a.length;j++){ if (a[i]> a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } }