import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
public class bubble {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
int t=0,flag = 1000;
String line = null;
List
list = new ArrayList
();
BufferedReader bReader = new BufferedReader(new FileReader("largeW.txt"));
while((line=bReader.readLine())!=null && t
tmp) {
high--;
}
list[low] = list[high]; //比中轴小的记录移到低端
while (low < high && list[low] < tmp) {
low++;
}
list[high] = list[low]; //比中轴大的记录移到高端
}
list[low] = tmp; //中轴记录到尾
return low; //返回中轴的位置
}
public static Integer[] _quickSort(Integer[] list, int low, int high) {
if (low < high) {
int middle = getMiddle(list, low, high); //将list数组进行一分为二
_quickSort(list, low, middle - 1); //对低字表进行递归排序
_quickSort(list, middle + 1, high); //对高字表进行递归排序
}
return list;
}
public static Integer[] bubbleSort(Integer a[]){//冒泡排序
int temp;
for(int j=0; j
a[i+1]){
temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
}
}
}
return a;
}
public static Integer[] mergeSort(Integer[] num, Integer[] num1, int s, int t) {//归并排序的递归算法
int m;
Integer[] num2 = new Integer[t + 1];
if (s == t)
num1[s] = num[s]; //待排序记录只有一个,递归结束
else {
m = (s + t) / 2;
mergeSort(num, num2, s, m);//左半部分递归调用
mergeSort(num, num2, m + 1, t);//右半部分递归调用
merg(num2, num1, s, m, t);//将两个已排序的子序列归并
}
return num1;
}
public static void merg(Integer[] num, Integer[] num1, int l, int m, int n) {//一次归并算法
int i, j, k;
i = l;
j = m + 1;
k = l;
while (i <= m && j <= n) {
if (num[i] < num[j])
num1[k++] = num[i++];
else {
num1[k++] = num[j++];
}
}
while (i <= m) {
num1[k++] = num[i++];
}
while (j <= n) {
num1[k++] = num[j++];
}
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交