File tree Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Expand file tree Collapse file tree 4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -49,3 +49,5 @@ Max Weinstein
49
49
Gibus Wearing Brony
50
50
<br >
51
51
Arun Sahadeo
52
+ <br >
53
+ NIFR91
Original file line number Diff line number Diff line change 116
116
{
117
117
"lang" : " lua" ,
118
118
"name" : " Lua"
119
+ },
120
+ {
121
+ "lang" : " crystal" ,
122
+ "name" : " Crystal"
119
123
}
124
+
120
125
]
121
126
}
122
127
}
Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
40
40
[ import:2-13, lang:"ti-83_basic"] ( code/ti83basic/BUBLSORT.txt )
41
41
{% sample lang="ruby" %}
42
42
[ import:3-13, lang:"ruby"] ( code/ruby/bubble.rb )
43
+ {% sample lang="crystal" %}
44
+ [ import:1-11, lang:"crystal"] ( code/crystal/bubble.cr )
43
45
{% endmethod %}
44
46
45
47
... And that's it for the simplest bubble sort method.
@@ -85,6 +87,8 @@ Program.cs
85
87
[ import, lang:"ti-83_basic"] ( code/ti83basic/BUBLSORT.txt )
86
88
{% sample lang="ruby" %}
87
89
[ import, lang: ruby "] ( code/ruby/bubble.rb )
90
+ {% sample lang="crystal" %}
91
+ [ import, lang:"crystal"] ( code/crystal/bubble.cr )
88
92
{% endmethod %}
89
93
90
94
<script >
Original file line number Diff line number Diff line change
1
+ def bubble_sort (arr )
2
+ arr = arr.dup
3
+ (0 ... arr.size).each do
4
+ (0 ... arr.size-1 ).each do |k |
5
+ if arr[k] > arr[k+ 1 ]
6
+ arr[k+ 1 ],arr[k] = arr[k],arr[k+ 1 ]
7
+ end
8
+ end
9
+ end
10
+ arr
11
+ end
12
+
13
+ def main
14
+ number = 10 .times.map{rand(0 ..1_000)}.to_a
15
+ pp " The array before sorting is #{ number } "
16
+ number = bubble_sort number
17
+ pp " The array after sorting is #{ number } "
18
+ end
19
+
20
+ main
You can’t perform that action at this time.
0 commit comments