-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort.java
More file actions
78 lines (62 loc) · 1.68 KB
/
Sort.java
File metadata and controls
78 lines (62 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package org.tj.algorithms;
import java.util.*;
/**
* Created by 001 on 16/8/16.
*/
public class Sort {
// 插入排序
// 直接插入排序
public static void straightInsertionSort(int []a){
int length = a.length;
for (int i=1;i<length;i++){
if (a[i]<a[i-1]){
}
}
}
static void quickSort(int [] a){
quickSort(a,0,a.length-1);
}
// 快排 平均时间复杂度 NlogN 最坏情况n2
static void quickSort(int [] a,int begin,int end){
int tmp = a[begin];
int i = begin,j = end;
if (begin<end){
while (begin<end){
while (begin<end && tmp<=a[end]){
end--;
}
a[begin] = a[end];
while (begin<end && tmp>a[begin]){
begin++;
}
a[end] = a[begin];
}
a[begin] = tmp;
quickSort(a,i,begin-1);
quickSort(a,end+1,j);
}
}
static void printArray(int a[]){
int j = a.length;
for (int i=0;i<j;i++){
System.out.print(" "+a[i]);
}
}
public static void main(String[] args) {
int[] a = {32,13,4,3,63,7,52,3,47};
// quickSort(a);
// straightInsertionSort(a);
// printArray(a);
List<Integer> list = new ArrayList<>();
for (int i=1;i<30;i++){
list.add(i);
}
Collections.shuffle(list);
for (int j=0;j<5;j++){
System.out.print(list.get(j)+" ");
}
// for (Object object : set.toArray()){
// System.out.println((Integer)object);
// }
}
}