您的位置:首页 > 其它

第三周----作业冒泡排序与归并排序

2014-03-27 23:03 260 查看
import java.io.*;

public class FileIn {

public static void main(String [] args){

System.out.println("程序在运行!");

long startTime=System.currentTimeMillis();

FileIn f=new FileIn();

f.file();

long endTime=System.currentTimeMillis();

System.out.println("运行时间:"+(endTime-startTime)+"毫秒");

}

public void file(){

try{

FileInputStream fis=new FileInputStream("largeW.txt");

InputStreamReader dis=new InputStreamReader(fis);

BufferedReader reader=new BufferedReader(dis);

String s;

int num=0;

long a[];

int j=0;

a=new long[1000000];

while((s=reader.readLine())!=null){

num++;

a[j]=Long.decode(s);

j++;

}

FileIn sort=new FileIn();

sort.bubblesort(a);

// sort.printl(a);

dis.close();

}catch(IOException e){

System.out.println(e);

}

}

public void printl(long[] a){

for(int i=0;i<a.length;i++){

System.out.println(a[i]);

}

}

public void bubblesort(long [] a){

int i,j;

long temp;

boolean flag;

for(i=0,flag=true;i<a.length-1&&flag;i++){

flag=false;

for(j=0;j<a.length-1-i;j++){

if(a[j]>a[j+1]){

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

flag=true;

}

}

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: