初中作文:留點(diǎn)責(zé)任給自己(精選12篇)
用JAVA實(shí)現(xiàn)一種排序,JAVA類(lèi)實(shí)現(xiàn)序列化的方法(二種)? 如在COLLECTION框架中,實(shí)現(xiàn)比較要實(shí)現(xiàn)什么樣的接口?
答:用插入法進(jìn)行排序代碼如下
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<num ;i++ )
{
al.add(new Integer(Math.abs(rand.nextInt()) % mod + 1));
System.out.println(”al["+i+"]=”+al.get(i));
}
}
public void SortIt()
{
Integer tempInt;
int MaxSize=1;
for(int i=1;i<al.size();i++)
{
tempInt = (Integer)al.remove(i);
if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue())
{
al.add(MaxSize,tempInt);
MaxSize++;
System.out.println(al.toString());
} else {
for (int j=0;j<MaxSize ;j++ )
{
if

(((Integer)al.get(j)).intValue()>=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<al.size();i++)
{
System.out.println(”al["+i+"]=”+al.get(i));
}
}
public static void main(String[] args)
{
InsertSort is = new InsertSort(10,100);
is.SortIt();
}
}
更多相關(guān)的文章推薦,大家敬請(qǐng)關(guān)注應(yīng)屆畢業(yè)生求職網(wǎng)的面試問(wèn)題欄目!
【初中作文:留點(diǎn)責(zé)任給自己】相關(guān)文章:
留點(diǎn)什么給自己作文03-19
留點(diǎn)挫折給自己作文04-16
留點(diǎn)自由給自己作文04-16
留點(diǎn)苦難給自己作文10-21
留點(diǎn)快樂(lè)給自己作文03-06
留點(diǎn)記憶給自己作文04-18
留點(diǎn)時(shí)間給自己作文04-18
留點(diǎn)尊嚴(yán)給自己作文12-02
- 相關(guān)推薦