Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions contents/bubble_sort/bubble_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
{% sample lang="py" %}
[import:4-9, lang:"python"](code/python/bubblesort.py)
{% sample lang="m" %}
[import:11-23, lang:"matlab"](code/matlab/bubblesort.m)
[import:1-13, lang:"matlab"](code/matlab/bubblesort.m)
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/bubbleSort.hs)
{% sample lang="cpp" %}
Expand All @@ -33,7 +33,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
{% sample lang="go" %}
[import:7-21, lang:"golang"](code/go/bubbleSort.go)
{% sample lang="racket" %}
[import:6-19, lang:"racket"](code/racket/bubbleSort.rkt)
[import:6-19, lang:"scheme"](code/racket/bubbleSort.rkt)
{% sample lang="swift" %}
[import:1-13, lang:"swift"](code/swift/bubblesort.swift)
{% sample lang="ti83b" %}
Expand Down Expand Up @@ -82,13 +82,13 @@ Program.cs
{% sample lang="go" %}
[import, lang:"golang"](code/go/bubbleSort.go)
{% sample lang="racket" %}
[import, lang:"racket"](code/racket/bubbleSort.rkt)
[import, lang:"scheme"](code/racket/bubbleSort.rkt)
{% sample lang="swift" %}
[import, lang:"swift"](code/swift/bubblesort.swift)
{% sample lang="ti83b" %}
[import, lang:"ti-83_basic"](code/ti83basic/BUBLSORT.txt)
{% sample lang="ruby" %}
[import, lang:ruby"](code/ruby/bubble.rb)
[import, lang:"ruby"](code/ruby/bubble.rb)
{% sample lang="crystal" %}
[import, lang:"crystal"](code/crystal/bubble.cr)
{% sample lang="php" %}
Expand Down
28 changes: 14 additions & 14 deletions contents/bubble_sort/code/matlab/bubblesort.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
function main()
array = floor( rand(1,7)*100 );
disp('Before Sorting:')
disp(array)

array = bubble_sort(array);
disp('After Sorting')
disp(array)
end

function sorted_array = bubble_sort(array)
for i=1:length(array)
for j=1:length(array)-i
function sorted_array = bubblesort(array)
for i = 1 : length(array)
for j = 1 : length(array) - i
if array(j) > array(j+1)
% swap elements in the list
temp = array(j);
Expand All @@ -19,7 +9,17 @@ function main()
end
end
end
sorted_array = array
sorted_array = array;
end

function main()
array = floor(rand(1, 7) * 100);
disp('Before Sorting:')
disp(array)

array = bubble_sort(array);
disp('After Sorting:')
disp(array)
end

main()
2 changes: 1 addition & 1 deletion contents/bubble_sort/code/racket/bubbleSort.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
[r (drop l 2)])
(cond [(= (- n counter) 2) (cons (min x y) (cons (max x y) r))]
[(cons (min x y) (pass (cons (max x y) r) (+ counter 1) n))])))


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