質問編集履歴
2
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
class Algorithm のMergeSortの設定はできたのですがそれを利用した配列のソートの仕方がわからない
|
test
CHANGED
File without changes
|
1
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
マージソートを使ったもので空欄3.4.5を教えて欲しいです
|
test
CHANGED
@@ -1,33 +1,125 @@
|
|
1
|
-
|
1
|
+
using System;
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
namespace
|
2
6
|
|
3
7
|
{
|
4
8
|
|
5
|
-
|
9
|
+
public class Algorithm // メソッドを置くためのクラス
|
6
10
|
|
7
|
-
{
|
11
|
+
{
|
8
12
|
|
9
|
-
i
|
13
|
+
public static void MergeSort<T>(T[] array, int first,int last, Func<T, T, bool> comp)
|
10
14
|
|
11
|
-
{
|
15
|
+
{
|
12
16
|
|
13
|
-
in
|
17
|
+
if (array != null && comp != null && 0 <= first && first <= last && last <= array.Length)
|
14
18
|
|
15
|
-
|
19
|
+
{
|
16
20
|
|
21
|
+
if(last - first > 1)
|
22
|
+
|
23
|
+
{
|
24
|
+
|
25
|
+
int middle = (first + last) / 2;
|
26
|
+
|
27
|
+
MergeSort(array, first, middle, comp);
|
28
|
+
|
17
|
-
MergeSort(array,middle,last,comp);
|
29
|
+
MergeSort(array,middle, last, comp);
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
Merge(array, first, middle, last, comp);
|
34
|
+
|
35
|
+
}
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
|
18
44
|
|
19
45
|
|
20
46
|
|
21
|
-
|
47
|
+
// end of class Algorithm
|
22
48
|
|
23
|
-
|
49
|
+
|
24
50
|
|
25
|
-
|
51
|
+
class Program
|
26
52
|
|
53
|
+
{
|
54
|
+
|
55
|
+
static void Main(string[] args)
|
56
|
+
|
57
|
+
{
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
// 処理対象の配列1
|
66
|
+
|
67
|
+
double[] voltages = new[] { 14.53, 14.26, 9.85, 9.81, 14.42, 28.66, 11.43, 16.41, 17.18, 13.57, 9.53, 4.74 };
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
// 処理対象の配列2
|
72
|
+
|
73
|
+
DateTime[] days = new[] {
|
74
|
+
|
75
|
+
new DateTime(2021, 7, 31), new DateTime(2021, 8, 20),
|
76
|
+
|
77
|
+
new DateTime(2021, 5, 6), new DateTime(2021, 8, 14),
|
78
|
+
|
79
|
+
new DateTime(2021, 5, 22), new DateTime(2021, 6, 24),
|
80
|
+
|
81
|
+
new DateTime(2021, 8, 19), new DateTime(2021, 7, 18),
|
82
|
+
|
27
|
-
}
|
83
|
+
};
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
// 処理対象の配列3
|
88
|
+
|
89
|
+
string[] foods = new[] {
|
90
|
+
|
91
|
+
"orange",
|
92
|
+
|
93
|
+
"grape",
|
94
|
+
|
95
|
+
"melon",
|
96
|
+
|
97
|
+
"apple",
|
98
|
+
|
99
|
+
"strawberry",
|
100
|
+
|
101
|
+
"banana",
|
102
|
+
|
103
|
+
"mango",
|
104
|
+
|
105
|
+
"peach",
|
106
|
+
|
107
|
+
"lemon",
|
108
|
+
|
109
|
+
"blackberry",
|
110
|
+
|
111
|
+
};
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
空欄3: MergeSort<T>()メソッドを使って 配列 voltages の全範囲を値の昇順にソートする
|
28
118
|
|
29
119
|
|
30
120
|
|
31
|
-
|
121
|
+
空欄4: MergeSort<T>()メソッドを使って配列 days の全範囲を日付の新しい順 (値の降順)にソートする
|
32
122
|
|
123
|
+
|
124
|
+
|
33
|
-
MergeSort<T>()メソッドを使って配列
|
125
|
+
空欄5: MergeSort<T>()メソッドを使って配列 foods の全範囲を辞書順(昇順)にソートする
|