teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

2021/07/14 03:09

投稿

RyodaiBS
RyodaiBS

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- マージソートを使っので空欄3.4.5教えて欲しいです
1
+ class Algorithm のMergeSortの設定はできたのですがそれ利用た配列のソートの仕方がわからな
body CHANGED
File without changes

1

2021/07/14 03:09

投稿

RyodaiBS
RyodaiBS

スコア0

title CHANGED
@@ -1,1 +1,1 @@
1
- MergeSortのMergeSort<T>()メッドを使って配列値を昇順にソート
1
+ マージートを使ったもので空欄3.4.5教えて欲しいで
body CHANGED
@@ -1,17 +1,63 @@
1
- **ボールドテキスト**public static void MergeSort<T>(T[] array,int first,int last ,Func<T,T,bool>comp)
1
+ using System;
2
+
3
+ namespace
2
4
  {
3
- if (array !=null && complete !=null && 0<= first && first <= last && last <=array.Length)
5
+ public class Algorithm // メソッドを置くためのクラス
4
- {
6
+ {
5
- if (last - first > 1)
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
- Merge(array,first,middle,last,comp);
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>()メソッドを使って配列voltagesの全範囲を値の昇順にソートする
63
+ 空欄5: MergeSort<T>()メソッドを使って配列 foods の全範囲を辞書順(昇順)にソートする