回答編集履歴
2
実行結果不正
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
こんな感じでどうでしょうか。
|
2
2
|
```VB
|
3
|
-
Private Data As Integer() = Enumerable.Range(1,
|
3
|
+
Private Data As Integer() = Enumerable.Range(1, 20).OrderBy(Of Guid)(Function(i As Integer) Guid.NewGuid()).ToArray()
|
4
4
|
|
5
5
|
Sub Main()
|
6
6
|
Console.WriteLine(String.Join(",", Data.Select(Function(i As Integer) i.ToString())))
|
@@ -40,6 +40,6 @@
|
|
40
40
|
```
|
41
41
|
|
42
42
|
実行結果
|
43
|
-
|
43
|
+
17,7,8,2,16,6,12,13,3,14,18,1,11,10,4,9,5,15,20,19
|
44
44
|
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20
|
45
45
|
|
1
何が気にいらなかったのだろう
test
CHANGED
@@ -1,52 +1,41 @@
|
|
1
1
|
こんな感じでどうでしょうか。
|
2
2
|
```VB
|
3
|
-
Private Data As Integer() = Enumerable.Range(1,
|
3
|
+
Private Data As Integer() = Enumerable.Range(1, 19).OrderBy(Of Guid)(Function(i As Integer) Guid.NewGuid()).ToArray()
|
4
4
|
|
5
5
|
Sub Main()
|
6
|
-
S
|
6
|
+
Console.WriteLine(String.Join(",", Data.Select(Function(i As Integer) i.ToString())))
|
7
7
|
DivisionSort(0, Data.Length - 1)
|
8
|
-
S
|
8
|
+
Console.WriteLine(String.Join(",", Data.Select(Function(i As Integer) i.ToString())))
|
9
9
|
Console.ReadKey()
|
10
10
|
End Sub
|
11
11
|
|
12
|
-
Private Sub ShowData()
|
13
|
-
Console.WriteLine(String.Join(",", Data.Select(Function(i) i.ToString()).ToArray()))
|
14
|
-
End Sub
|
15
|
-
|
16
12
|
Private Sub DivisionSort(minNo As Integer, maxNo As Integer)
|
17
|
-
If minNo >= maxNo Then Return
|
18
|
-
Dim pivot As Integer = Median(Data(minNo), Data((minNo + maxNo) \ 2), Data(maxNo))
|
19
13
|
Dim i As Integer = minNo
|
20
14
|
Dim j As Integer = maxNo
|
15
|
+
Dim pivot As Integer = Data((minNo + maxNo) \ 2)
|
21
|
-
|
16
|
+
Dim temp As Integer
|
17
|
+
Do
|
22
|
-
While
|
18
|
+
While Data(i) < pivot
|
23
19
|
i += 1
|
24
20
|
End While
|
25
|
-
While
|
21
|
+
While pivot < Data(j)
|
26
22
|
j -= 1
|
27
23
|
End While
|
24
|
+
|
28
|
-
If i > j Then Exit
|
25
|
+
If i >= j Then Exit Do
|
26
|
+
|
29
|
-
|
27
|
+
temp = Data(i)
|
30
|
-
|
28
|
+
Data(i) = Data(j)
|
31
|
-
|
29
|
+
Data(j) = temp
|
32
30
|
i += 1
|
33
31
|
j -= 1
|
32
|
+
Loop
|
34
|
-
|
33
|
+
If minNo < i - 1 Then
|
35
|
-
DivisionSort(minNo, i - 1)
|
34
|
+
DivisionSort(minNo, i - 1)
|
35
|
+
End If
|
36
|
+
If j + 1 < maxNo Then
|
36
|
-
DivisionSort(
|
37
|
+
DivisionSort(j + 1, maxNo)
|
37
|
-
End
|
38
|
+
End If
|
38
|
-
|
39
|
-
Private Function Median(a As Integer, b As Integer, c As Integer) As Integer
|
40
|
-
If (a > b) Then Swap(a, b)
|
41
|
-
If (a > c) Then Swap(a, c)
|
42
|
-
If (b > c) Then Swap(b, c)
|
43
|
-
Return b
|
44
|
-
End Function
|
45
|
-
|
46
|
-
Private Sub Swap(ByRef a As Integer, ByRef b As Integer)
|
47
|
-
Dim tmp As Integer = a
|
48
|
-
a = b
|
49
|
-
b = tmp
|
50
39
|
End Sub
|
51
40
|
```
|
52
41
|
|