質問編集履歴
2
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
class Algorithm のMergeSortの設定はできたのですがそれを利用した配列のソートの仕方がわからない
|
body
CHANGED
File without changes
|
1
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
マージソートを使ったもので空欄3.4.5を教えて欲しいです
|
body
CHANGED
@@ -1,17 +1,63 @@
|
|
1
|
-
|
1
|
+
using System;
|
2
|
+
|
3
|
+
namespace
|
2
4
|
{
|
3
|
-
|
5
|
+
public class Algorithm // メソッドを置くためのクラス
|
4
|
-
{
|
6
|
+
{
|
5
|
-
|
7
|
+
public static void MergeSort<T>(T[] array, int first,int last, Func<T, T, bool> comp)
|
6
|
-
{
|
8
|
+
{
|
9
|
+
if (array != null && comp != null && 0 <= first && first <= last && last <= array.Length)
|
10
|
+
{
|
11
|
+
if(last - first > 1)
|
12
|
+
{
|
7
|
-
int middle =(first + last) /2;
|
13
|
+
int middle = (first + last) / 2;
|
8
|
-
MergeSort(array,first,middle,comp);
|
14
|
+
MergeSort(array, first, middle, comp);
|
9
|
-
MergeSort(array,middle,last,comp);
|
15
|
+
MergeSort(array,middle, last, comp);
|
16
|
+
|
17
|
+
Merge(array, first, middle, last, comp);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
10
23
|
|
24
|
+
// end of class Algorithm
|
25
|
+
|
26
|
+
class Program
|
27
|
+
{
|
11
|
-
|
28
|
+
static void Main(string[] args)
|
29
|
+
{
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
// 処理対象の配列1
|
34
|
+
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 };
|
35
|
+
|
36
|
+
// 処理対象の配列2
|
37
|
+
DateTime[] days = new[] {
|
38
|
+
new DateTime(2021, 7, 31), new DateTime(2021, 8, 20),
|
39
|
+
new DateTime(2021, 5, 6), new DateTime(2021, 8, 14),
|
40
|
+
new DateTime(2021, 5, 22), new DateTime(2021, 6, 24),
|
41
|
+
new DateTime(2021, 8, 19), new DateTime(2021, 7, 18),
|
12
|
-
}
|
42
|
+
};
|
43
|
+
|
44
|
+
// 処理対象の配列3
|
45
|
+
string[] foods = new[] {
|
46
|
+
"orange",
|
47
|
+
"grape",
|
48
|
+
"melon",
|
49
|
+
"apple",
|
50
|
+
"strawberry",
|
51
|
+
"banana",
|
52
|
+
"mango",
|
53
|
+
"peach",
|
54
|
+
"lemon",
|
55
|
+
"blackberry",
|
13
|
-
}
|
56
|
+
};
|
57
|
+
|
58
|
+
|
14
|
-
|
59
|
+
空欄3: MergeSort<T>()メソッドを使って 配列 voltages の全範囲を値の昇順にソートする
|
15
60
|
|
16
|
-
|
61
|
+
空欄4: MergeSort<T>()メソッドを使って配列 days の全範囲を日付の新しい順 (値の降順)にソートする
|
62
|
+
|
17
|
-
MergeSort<T>()メソッドを使って配列
|
63
|
+
空欄5: MergeSort<T>()メソッドを使って配列 foods の全範囲を辞書順(昇順)にソートする
|