diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000000000000000000000000000000000000..739758834431274bbb950b8315c107d007da3849 --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..5c98b428844d9f7d529e2b6fb918d15bf072f3df --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000000000000000000000000000000000..639900d13c6182e452e33a3bd638e70a0146c785 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000000000000000000000000000000000..375e35c14bbe6b32bb1a2d81eb77c40cbc1d2383 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000000000000000000000000000000000..94a25f7f4cb416c083d265558da75d457237d671 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lec08-sort.iml b/lec08-sort.iml new file mode 100644 index 0000000000000000000000000000000000000000..8021953ed9f8cc6cd6d71c79462bad4cd2b5394c --- /dev/null +++ b/lec08-sort.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/work/BubbleSort/BubbleSort.class b/work/BubbleSort/BubbleSort.class new file mode 100644 index 0000000000000000000000000000000000000000..9ce42c9266d6625452361139d2a77d1a702a631a Binary files /dev/null and b/work/BubbleSort/BubbleSort.class differ diff --git a/work/BubbleSort/BubbleSort.java b/work/BubbleSort/BubbleSort.java new file mode 100644 index 0000000000000000000000000000000000000000..6aed21c752a5893ee322b33c5736e4faad427e40 --- /dev/null +++ b/work/BubbleSort/BubbleSort.java @@ -0,0 +1,19 @@ +import java.util.*; +public class BubbleSort { + public static void main(String[] args) { + int[] arr = {12,56,3,78,39};//,1,2,5,4,6,7,8,33,22,44,55,66,77 + long n1 = System.nanoTime(); + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr.length - 1 - i; 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)); + long n2 = System.nanoTime(); + System.out.printf("\n冒泡排序用时:"+(n2-n1)/1000000+"毫秒\n"); + } +} \ No newline at end of file diff --git a/work/InsertSort/InsertSort.class b/work/InsertSort/InsertSort.class new file mode 100644 index 0000000000000000000000000000000000000000..9f704a3238c63bbd749203d21e5034e06ec21e2b Binary files /dev/null and b/work/InsertSort/InsertSort.class differ diff --git a/work/InsertSort/InsertSort.java b/work/InsertSort/InsertSort.java new file mode 100644 index 0000000000000000000000000000000000000000..12441f299f959dc53044a1c31bc7772134b3c00f --- /dev/null +++ b/work/InsertSort/InsertSort.java @@ -0,0 +1,27 @@ +import java.util.*; +public class InsertSort{ + public static void main(String[] args) { + int[] array={12,56,3,78,39}; + double n1 = System.nanoTime(); + test(array); + double n2 = System.nanoTime(); + System.out.printf("\n插入排序用时:"+(n2-n1)/1000000+"毫秒\n"); + } + + public static void test(int[] array) { + int i,j,temp; + for(i=1;i=0;--j) {//注意这里--j,有机会让j到-1 + if(temp>array[j]) { + break; + }else { + array[j+1]=array[j]; + } + } + array[j+1]=temp; + } + System.out.println(Arrays.toString(array)); + } +} + diff --git a/work/MergeSort/Main.class b/work/MergeSort/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..2cefec554cf196ebb2ca17909cc12af70f1df685 Binary files /dev/null and b/work/MergeSort/Main.class differ diff --git a/work/MergeSort/Main.java b/work/MergeSort/Main.java new file mode 100644 index 0000000000000000000000000000000000000000..1e5c270ddb6c3b53393b3ee7e9eaab57f8c8d9c2 --- /dev/null +++ b/work/MergeSort/Main.java @@ -0,0 +1,49 @@ +import java.util.Arrays; +public class Main{ + public static void main(String[] args){ + int[] arr = {12,56,3,78,39}; + double n1 = System.nanoTime(); + sort(arr,0,arr.length-1); + System.out.println(Arrays.toString(arr)); + double n2 = System.nanoTime(); + System.out.printf("\n归并排序用时:"+(n2-n1)/1000000+"毫秒\n"); + } + + public static int[] sort(int[] a,int low,int high){ + int mid = (low+high)/2; + if(low= pivot) { + high--; + } + //将比 pivot 小的元素移向低端 + arr[low] = arr[high]; + while(low 0; step /= 2) { + //对一个步长区间进行比较 [step,arr.length) + for (int i = step; i < arr.length; i++) { + int value = arr[i]; + int j; + + //对步长区间中具体的元素进行比较 + for (j = i - step; j >= 0 && arr[j] > value; j -= step) { + //j为左区间的取值,j+step为右区间与左区间的对应值。 + arr[j + step] = arr[j]; + } + //此时step为一个负数,[j + step]为左区间上的初始交换值 + arr[j + step] = value; + } + } + } +} \ No newline at end of file diff --git "a/work/\347\256\227\346\263\225\347\224\250\346\227\266/1.png" "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/1.png" new file mode 100644 index 0000000000000000000000000000000000000000..8dd1ac634a16530c3eba6260a6ada4f881242112 Binary files /dev/null and "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/1.png" differ diff --git "a/work/\347\256\227\346\263\225\347\224\250\346\227\266/2.png" "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/2.png" new file mode 100644 index 0000000000000000000000000000000000000000..0ec8c6e0181c8325810ef6548cc09c525ba2c4d0 Binary files /dev/null and "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/2.png" differ diff --git "a/work/\347\256\227\346\263\225\347\224\250\346\227\266/3.png" "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/3.png" new file mode 100644 index 0000000000000000000000000000000000000000..f424b1aaed8f0a26f3a43162962f0cb589300172 Binary files /dev/null and "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/3.png" differ diff --git "a/work/\347\256\227\346\263\225\347\224\250\346\227\266/4.png" "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/4.png" new file mode 100644 index 0000000000000000000000000000000000000000..e80e0f9f8b9dc3edd82a81551ff24a16c1c27770 Binary files /dev/null and "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/4.png" differ diff --git "a/work/\347\256\227\346\263\225\347\224\250\346\227\266/5.png" "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/5.png" new file mode 100644 index 0000000000000000000000000000000000000000..c5d44d6cbf98f08036a3fcedb38962aaf689a617 Binary files /dev/null and "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/5.png" differ diff --git "a/work/\347\256\227\346\263\225\347\224\250\346\227\266/6.png" "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/6.png" new file mode 100644 index 0000000000000000000000000000000000000000..8632a5d5960c5327d9e08120d41687077e18299f Binary files /dev/null and "b/work/\347\256\227\346\263\225\347\224\250\346\227\266/6.png" differ