回答編集履歴
3
修正
test
CHANGED
@@ -14,6 +14,8 @@
|
|
14
14
|
|
15
15
|
int a[100];
|
16
16
|
|
17
|
+
int l = sizeof(a) / sizeof(int);
|
18
|
+
|
17
19
|
|
18
20
|
|
19
21
|
for(i = 0;i < 100; i++){
|
@@ -24,9 +26,9 @@
|
|
24
26
|
|
25
27
|
|
26
28
|
|
27
|
-
for(i = 0; i <
|
29
|
+
for(i = 0; i < l; i++){
|
28
|
-
|
30
|
+
|
29
|
-
for(j = 1; j <
|
31
|
+
for(j = 1; j < l; j++){
|
30
32
|
|
31
33
|
if(a[j] > a[j + 1]){
|
32
34
|
|
2
修正
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
for(i = 0; i < sizeof(a) / sizeof(int); i++){
|
28
28
|
|
29
|
-
for(j =
|
29
|
+
for(j = 1; j < sizeof(a) / sizeof(int); j++){
|
30
30
|
|
31
31
|
if(a[j] > a[j + 1]){
|
32
32
|
|
1
修正
test
CHANGED
@@ -24,9 +24,9 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
for(i = 0; i <
|
27
|
+
for(i = 0; i < sizeof(a) / sizeof(int); i++){
|
28
|
-
|
28
|
+
|
29
|
-
for(j = 0; j <
|
29
|
+
for(j = 0; j < sizeof(a) / sizeof(int) - 1; j++){
|
30
30
|
|
31
31
|
if(a[j] > a[j + 1]){
|
32
32
|
|
@@ -263,3 +263,113 @@
|
|
263
263
|
```
|
264
264
|
|
265
265
|
見よう見まねでやってみました。
|
266
|
+
|
267
|
+
```Ruby
|
268
|
+
|
269
|
+
# encoding: utf-8
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
a = Array.new(100).map { rand(100) }
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
a.size.times do
|
278
|
+
|
279
|
+
(a.size - 1).times do |x|
|
280
|
+
|
281
|
+
a[x], a[x + 1] = a[x + 1], a[x] if a[x] > a[x + 1]
|
282
|
+
|
283
|
+
end
|
284
|
+
|
285
|
+
end
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
p a
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
```
|
296
|
+
|
297
|
+
Rubyバージョン
|
298
|
+
|
299
|
+
```C#
|
300
|
+
|
301
|
+
using System;
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
namespace sort
|
306
|
+
|
307
|
+
{
|
308
|
+
|
309
|
+
class Program
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
static void Main(string[] args)
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
int[] a = new int[100];
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
int seed = Environment.TickCount;
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
for(int i = 0; i < 100; i++)
|
326
|
+
|
327
|
+
{
|
328
|
+
|
329
|
+
Random rand = new Random(seed++);
|
330
|
+
|
331
|
+
a[i] = rand.Next(100);
|
332
|
+
|
333
|
+
}
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
for(int i = 0; i < a.Length; i++)
|
338
|
+
|
339
|
+
{
|
340
|
+
|
341
|
+
for(int j = 0; j < a.Length - 1; j++)
|
342
|
+
|
343
|
+
{
|
344
|
+
|
345
|
+
if(a[j] > a[j + 1])
|
346
|
+
|
347
|
+
{
|
348
|
+
|
349
|
+
int t = a[j + 1];
|
350
|
+
|
351
|
+
a[j + 1] = a[j];
|
352
|
+
|
353
|
+
a[j] = t;
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
foreach(int i in a) Console.WriteLine(i);
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
```
|
374
|
+
|
375
|
+
C# バージョン。
|