数据结构的东西忘了好多,要找新工作了,复习复习。
package com.test;
import java.util.Arrays;
import java.util.Date;
public class Sort{
public static void main(String[] args) {
// gerneraMethod("1", 2 , new Date());//做个泛型的案例给你看看就好
Integer[] A = new Integer[] {null, 19, 8, -38, 49, 65, 97 , 76, 13, 27, 4 , 18, 57};
Integer[] B = new Integer[] { 19, 8, -38, 49, 65, 97 , 76, 13, 27, 4 , 18, 57};
// ShellSort(A);
// InsertSort(A);
// A[0] = null;
// ShellSort(A);
// BubbleSort(B);
// TowWayBubbleSort(B);
// int low=0, hight=B.length-1;
// QuickSort(B, low, hight);
SelectSort(B);
PrintArray(B);
}
//直接插入排序
public static void InsertSort(Integer[] A) {
int j;
for(int i=2; iA[i]) {
A[0] = A[i];
for(j=i-1; A[0]=low; --j) {
A[j+1]=A[j];//将数据往后移
}
A[low] = A[0];//插入位置
}
}
//希尔排序
private static void ShellSort(Integer[] A) {
int i, j, dk;
for(dk=A.length/2; dk>=1; dk/=2 ) {
for(i=dk+1; i0 && A[0]i; j--) {
if(A[j-1]>A[j]) {
temp = A[j-1];
A[j-1] = A[j];
A[j] = temp;
flag = true;//发生排序就是还未有序
}
}
}
}
//双向冒泡排序,及第一次从前向后直到将最大的数置于后面,
//第二次将最小的数置于最前方
private static void TowWayBubbleSort(Integer[] A) {
int i, j, low=0, high = A.length-1;
boolean flag=true;
while (lowA[j]) {
swag(A, j-1, j);
flag = true;
}
}
low++;
}
}
//快速排序
private static void QuickSort(Integer[] A, Integer low, Integer hight) {
if(low=pivot) --hight;//符合条件不用换位置,继续左走
A[low] = A[hight];
while(low void gerneraMethod(T... elements) {
for(T element : elements) {
if(element instanceof Integer) {
System.out.println("处理的。。。这里是整型");
}else if (element instanceof String) {
System.out.println("处理的。。。这里是字符串");
}else if (element instanceof Double) {
System.out.println("处理的。。。这里是双精度浮点");
}else if (element instanceof Float) {
System.out.println("处理的。。。这里是单精度浮点");
}else if (element instanceof Long) {
System.out.println("处理的。。。这里是单精度浮点");
}else if (element instanceof Boolean) {
System.out.println("处理的。。。这里是布尔值");
}else if (element instanceof Date) {
System.out.println("处理的。。。这里是时间");
}
}
}
}



