- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmethods.java
More file actions
Latest commit
58 lines (50 loc) · 1.5 KB
/
Copy pathmethods.java
File metadata and controls
58 lines (50 loc) · 1.5 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
importjava.util.Random;
importjava.util.Scanner;
publicclassmethods {
staticint[] fillArray(intsize) {
int[] array = newint[size];
for (inti = 0; i < array.length; i++) {
Randomrnd = newRandom();
array[i] = rnd.nextInt(100);
}
returnarray;
}
staticintinputNum(Stringmsg) {
ScanneriScanner = newScanner(System.in);
System.out.print(msg);
intnum = iScanner.nextInt();
iScanner.close();
returnnum;
}
staticvoidshowArray(int[] array){
for (inti : array) {
System.out.printf("%d ", i);
}
System.out.println();
}
staticvoidquickSort(int[] sortArray, intlow, inthigh) {
if (sortArray.length == 0 || low >= high)
return;
intmiddle = low + (high - low) / 2;
intborder = sortArray[middle];
inti = low, j = high;
while (i <= j) {
while (sortArray[i] < border)
i++;
while (sortArray[j] > border)
j--;
if (i <= j) {
intswap = sortArray[i];
sortArray[i] = sortArray[j];
sortArray[j] = swap;
i++;
j--;
}
}
// рекурсия для сортировки левой и правой части
if (low < j)
quickSort(sortArray, low, j);
if (high > i)
quickSort(sortArray, i, high);
}
}