如题,这个方法.我用java写出来的方法.这么长...
可是,这个要写在actionscript里面,但是actionscript里面没有java的那么多好用的方法.
谁能求解出这道智力题?用最好用actionscript写出来,不要用Collections,iterator 迭代啊什么的...
public class BubbleSort implements Sort{
public void sort(int[] a) {
this.bubble(a,false);
}
public static void bubble(int[] number,boolean b) {
boolean flag = true;
for(int i = 0; i < number.length-1 && flag; i++) {
flag = false;
for(int j = 0; j < number.length-i-1; j++) {
if(same(number[j+1] < number[j],b)) {
swap(number, j+1, j);
flag = true;
}
}
}
}
private static boolean same(boolean a ,boolean b){
if(a==b){
return true;
}
return false;
}
private static void swap(int[] number, int i, int j) {
int t = number[i];
number[i] = number[j];
number[j] = t;
}
public static int frequency(int[] c, int o) {
int result = 0;
for (int i = 0; i < c.length; i++) {
if(o==c[i]){
result++;
}
}
return result;
}
@SuppressWarnings("unchecked")
public static void main(String[] args) {
int[] a=new int[]{1,1,1,9,9,3,3,5,5,5,5,7,2,2,2};
new BubbleSort().sort(a);
int d=1;
List list=new ArrayList<Obj>();
for (int i = 0; i < a.length; i=i+d) {
d=BubbleSort.frequency(a,a[i]);
Obj oo=new Obj(d,a[i]);
list.add(oo);
}
Collections.sort(list,new Comparator<Obj>(){
public int compare(Obj o1, Obj o2) {
return o2.a-o1.a;
}});
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
Obj object = (Obj) iterator.next();
for (int i = 0; i <object.a; i++) {
System.out.print(object.b+" ");
}
}
}
}