Skip to content

Commit a1a078d

Browse files
berquistjiegillet
authored andcommitted
Bubble sort: run MATLAB implementation and Markdown fixes (#350)
* Racket should be highlighted as Scheme. * Missing quote for Ruby syntax highlighting directive * Run code in MATLAB bubble sort implementation
1 parent e5ddeba commit a1a078d

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

contents/bubble_sort/bubble_sort.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
2121
{% sample lang="py" %}
2222
[import:4-9, lang:"python"](code/python/bubblesort.py)
2323
{% sample lang="m" %}
24-
[import:11-23, lang:"matlab"](code/matlab/bubblesort.m)
24+
[import:1-13, lang:"matlab"](code/matlab/bubblesort.m)
2525
{% sample lang="hs" %}
2626
[import, lang:"haskell"](code/haskell/bubbleSort.hs)
2727
{% sample lang="cpp" %}
@@ -33,7 +33,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
3333
{% sample lang="go" %}
3434
[import:7-21, lang:"golang"](code/go/bubbleSort.go)
3535
{% sample lang="racket" %}
36-
[import:6-19, lang:"racket"](code/racket/bubbleSort.rkt)
36+
[import:6-19, lang:"scheme"](code/racket/bubbleSort.rkt)
3737
{% sample lang="swift" %}
3838
[import:1-13, lang:"swift"](code/swift/bubblesort.swift)
3939
{% sample lang="ti83b" %}
@@ -84,13 +84,13 @@ Trust me, there are plenty of more complicated algorithms that do precisely the
8484
{% sample lang="go" %}
8585
[import, lang:"golang"](code/go/bubbleSort.go)
8686
{% sample lang="racket" %}
87-
[import, lang:"racket"](code/racket/bubbleSort.rkt)
87+
[import, lang:"scheme"](code/racket/bubbleSort.rkt)
8888
{% sample lang="swift" %}
8989
[import, lang:"swift"](code/swift/bubblesort.swift)
9090
{% sample lang="ti83b" %}
9191
[import, lang:"ti-83_basic"](code/ti83basic/BUBLSORT.txt)
9292
{% sample lang="ruby" %}
93-
[import, lang:ruby"](code/ruby/bubble.rb)
93+
[import, lang:"ruby"](code/ruby/bubble.rb)
9494
{% sample lang="crystal" %}
9595
[import, lang:"crystal"](code/crystal/bubble.cr)
9696
{% sample lang="php" %}
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
function main()
2-
array = floor( rand(1,7)*100 );
3-
disp('Before Sorting:')
4-
disp(array)
5-
6-
array = bubble_sort(array);
7-
disp('After Sorting')
8-
disp(array)
9-
end
10-
11-
function sorted_array = bubble_sort(array)
12-
for i=1:length(array)
13-
for j=1:length(array)-i
1+
function sorted_array = bubblesort(array)
2+
for i = 1 : length(array)
3+
for j = 1 : length(array) - i
144
if array(j) > array(j+1)
155
% swap elements in the list
166
temp = array(j);
@@ -19,7 +9,17 @@ function main()
199
end
2010
end
2111
end
22-
sorted_array = array
12+
sorted_array = array;
2313
end
2414

15+
function main()
16+
array = floor(rand(1, 7) * 100);
17+
disp('Before Sorting:')
18+
disp(array)
19+
20+
array = bubble_sort(array);
21+
disp('After Sorting:')
22+
disp(array)
23+
end
2524

25+
main()

contents/bubble_sort/code/racket/bubbleSort.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
[r (drop l 2)])
1717
(cond [(= (- n counter) 2) (cons (min x y) (cons (max x y) r))]
1818
[(cons (min x y) (pass (cons (max x y) r) (+ counter 1) n))])))
19-
19+
2020

2121
((lambda (x) (display (bubbleSort x))) (read))

0 commit comments

Comments
 (0)