用JAVA实现一种排序,JAVA类实现序列化的方法(二种)
2023-06-30
用JAVA实现一种排序,JAVA类实现序列化的方法(二种)? 如在COLLECTION框架中,实现比较要实现什么样的接口?
答:用插入法进行排序代码如下
package test;
import java.util.*;
class InsertSort
ArrayList al;
public InsertSort(int num,int mod)
al = new ArrayList(num);
Random rand = new Random();
System.out.println(“The ArrayList Sort Before:”);
for (int i=0;i=((Integer)al.get(MaxSize-1)).intValue())
al.add(MaxSize,tempInt);
MaxSize++;
System.out.println(al.toString());
else
for (int j=0;j=tempInt.intValue())
al.add(j,tempInt);
MaxSize++;
System.out.println(al.toString());
break;
System.out.println(“The ArrayList Sort After:”);
for(int i=0;i
System.out.println(“al["+i+"]=”+al.get(i));
public static void main(String[] args)
InsertSort is = new InsertSort(10,100);
is.SortIt();