Skip to content

Commit 216e7a5

Browse files
committed
no message
1 parent ab622fa commit 216e7a5

13 files changed

Lines changed: 185 additions & 0 deletions

File tree

854 Bytes
Binary file not shown.
2.11 KB
Binary file not shown.

build/classes/main/org/tj/sort/BinarySearch.class renamed to build/classes/main/org/tj/algorithms/sort/BinarySearch.class

1.53 KB
Binary file not shown.
1.35 KB
Binary file not shown.
612 Bytes
Binary file not shown.
1.03 KB
Binary file not shown.
1.01 KB
Binary file not shown.
1001 Bytes
Binary file not shown.
2.27 KB
Binary file not shown.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.tj.algorithms;
2+
3+
import java.util.*;
4+
5+
/**
6+
* Created by 001 on 16/8/16.
7+
*/
8+
public class Sort {
9+
10+
// 插入排序
11+
// 直接插入排序
12+
public static void straightInsertionSort(int []a){
13+
int length = a.length;
14+
for (int i=1;i<length;i++){
15+
if (a[i]<a[i-1]){
16+
17+
}
18+
}
19+
}
20+
21+
22+
static void quickSort(int [] a){
23+
quickSort(a,0,a.length-1);
24+
}
25+
// 快排 平均时间复杂度logN 最坏情况n2
26+
static void quickSort(int [] a,int begin,int end){
27+
int tmp = a[begin];
28+
int i = begin,j = end;
29+
30+
if (begin<end){
31+
while (begin<end){
32+
while (begin<end && tmp<=a[end]){
33+
end--;
34+
}
35+
a[begin] = a[end];
36+
37+
while (begin<end && tmp>a[begin]){
38+
begin++;
39+
}
40+
a[end] = a[begin];
41+
}
42+
a[begin] = tmp;
43+
quickSort(a,i,begin-1);
44+
quickSort(a,end+1,j);
45+
}
46+
}
47+
48+
49+
50+
51+
52+
static void printArray(int a[]){
53+
int j = a.length;
54+
for (int i=0;i<j;i++){
55+
System.out.print(" "+a[i]);
56+
}
57+
}
58+
59+
public static void main(String[] args) {
60+
int[] a = {32,13,4,3,63,7,52,3,47};
61+
// quickSort(a);
62+
// straightInsertionSort(a);
63+
// printArray(a);
64+
65+
List<Integer> list = new ArrayList<>();
66+
for (int i=1;i<30;i++){
67+
list.add(i);
68+
}
69+
Collections.shuffle(list);
70+
for (int j=0;j<5;j++){
71+
System.out.print(list.get(j)+" ");
72+
}
73+
// for (Object object : set.toArray()){
74+
// System.out.println((Integer)object);
75+
// }
76+
77+
}
78+
}

0 commit comments

Comments
 (0)