回答編集履歴
1
スケルトンを明示しました。
test
CHANGED
@@ -27,3 +27,139 @@
|
|
27
27
|
|
28
28
|
|
29
29
|
頑張って下さい。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
Javaの基礎を理解されていないようですね。
|
34
|
+
|
35
|
+
取り敢えず、スケルトン(骨組み)を示すとこんな感じになります。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
/**
|
40
|
+
|
41
|
+
* クイックソート
|
42
|
+
|
43
|
+
*/
|
44
|
+
|
45
|
+
public class QuickSortTest
|
46
|
+
|
47
|
+
{
|
48
|
+
|
49
|
+
public static void main(String[] args)
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
// ソート用の整数配列
|
54
|
+
|
55
|
+
int[] iarray = new int[10];
|
56
|
+
|
57
|
+
・
|
58
|
+
|
59
|
+
ファイルから読むなどの前準備
|
60
|
+
|
61
|
+
・
|
62
|
+
|
63
|
+
if(c.equals("baburu")) {
|
64
|
+
|
65
|
+
// バブルソート実行
|
66
|
+
|
67
|
+
bubbleSort(iarray);
|
68
|
+
|
69
|
+
}
|
70
|
+
|
71
|
+
else if(c.equals("quick")){
|
72
|
+
|
73
|
+
// クイックソート実行
|
74
|
+
|
75
|
+
quickSort(iarray, 0, iarray.length-1);
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
//結果表示
|
80
|
+
|
81
|
+
displayResult(iarray);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
/**
|
90
|
+
|
91
|
+
* バブルソートを行うメソッド
|
92
|
+
|
93
|
+
* @param array ソート対象配列
|
94
|
+
|
95
|
+
*/
|
96
|
+
|
97
|
+
public static void bubbleSort(int[] array)
|
98
|
+
|
99
|
+
{
|
100
|
+
|
101
|
+
・
|
102
|
+
|
103
|
+
バブルソートの処理
|
104
|
+
|
105
|
+
・
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
/**
|
114
|
+
|
115
|
+
* クイックソートを行うメソッド
|
116
|
+
|
117
|
+
* @param array ソート対象配列
|
118
|
+
|
119
|
+
* @param leftIndex 左開始点
|
120
|
+
|
121
|
+
* @param rightIndex 右開始点
|
122
|
+
|
123
|
+
*/
|
124
|
+
|
125
|
+
public static void quickSort(int[] array, int leftIndex, int rightIndex)
|
126
|
+
|
127
|
+
{
|
128
|
+
|
129
|
+
・
|
130
|
+
|
131
|
+
クイックソートの処理
|
132
|
+
|
133
|
+
・
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
/**
|
140
|
+
|
141
|
+
* 結果を出力
|
142
|
+
|
143
|
+
* @param array 配列
|
144
|
+
|
145
|
+
*/
|
146
|
+
|
147
|
+
public static void displayResult(int[] array)
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
for(int i : array)
|
152
|
+
|
153
|
+
{
|
154
|
+
|
155
|
+
System.out.println(String.valueOf(i) + " ");
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
System.out.println("");
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|