This commit is contained in:
fanxb 2019-05-16 19:59:29 +08:00
parent abfc0fbabc
commit 5e7ebf99f9
4 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,6 @@
public class Main {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}

View File

@ -0,0 +1,27 @@
package sort.exchange;
import java.util.Arrays;
/**
* 类功能简述冒泡排序
* 类功能详述冒泡排序故名思义就是每轮循环将一个最大或者最小的数放到无序部分的顶部知道所有的数都是有序的
*
* @author fanxb
* @date 2019/5/15 17:27
*/
public class BubbleSort {
public static void main(String[] args) {
int[] arr = {4, 12, 2, 8, 453, 1, 59, 33};
for (int i = 0, length = arr.length; i < arr.length - 1; i++) {
for (int j = 0, tempLength = length - 1 - i; j < tempLength; j++) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
System.out.println(Arrays.toString(arr));
}
}
}

View File

@ -0,0 +1,42 @@
package sort.exchange;
import util.ArrayUtil;
import java.util.Arrays;
/**
* 类功能简述快速排序
* 类功能详述使用了分治的思想先取一个数然后让这个数的左边都是小于等于它的右边都大于等于它然后左边右边分布做同样的处理
* 直到所有的数都有序
*
* @author fanxb
* @date 2019/5/15 17:35
*/
public class QuickSort {
private static void deal(Integer[] arr, int start, int end) {
if (start >= end) {
return;
}
int base = arr[start], i = start, j = end;
while (i < j) {
while (arr[i] <= base && i < end) {
i++;
}
while (arr[j] >= base && j > start) {
j--;
}
if (i < j) {
ArrayUtil.swap(arr, i, j);
}
}
System.out.println(Arrays.toString(arr));
deal(arr, start, i);
deal(arr, j, end);
}
public static void main(String[] args) {
Integer[] arr = {4, 3, 1, 89, 5};
deal(arr, 0, arr.length - 1);
}
}

View File

@ -0,0 +1,17 @@
package util;
/**
* 类功能简述数组工具栏
* 类功能详述
*
* @author fanxb
* @date 2019/5/15 17:43
*/
public class ArrayUtil {
public static void swap(Object[] arr, int i, int j) {
Object temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}