Skip to content

Adding Example Code to Sorting Algorithms #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2018
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
52 changes: 42 additions & 10 deletions contents/bogo_sort/bogo_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,55 @@ In code, it looks something like this:

{% method %}
{% sample lang="jl" %}
[import:1-14, lang:"julia"](code/julia/bogo.jl)
[import:10-14, lang:"julia"](code/julia/bogo.jl)
{% sample lang="cs" %}
[import:9-15, lang:"csharp"](code/csharp/BogoSort.cs)
{% sample lang="clj" %}
[import:2-11, lang:"clojure"](code/clojure/bogo.clj)
[import:7-11, lang:"clojure"](code/clojure/bogo.clj)
{% sample lang="c" %}
[import:4-29, lang:"c_cpp"](code/c/bogo_sort.c)
[import:25-29, lang:"c_cpp"](code/c/bogo_sort.c)
{% sample lang="java" %}
[import:2-17, lang:"java"](code/java/bogo.java)
[import:2-6, lang:"java"](code/java/bogo.java)
{% sample lang="js" %}
[import:1-16, lang:"javascript"](code/javascript/bogo.js)
[import:11-15, lang:"javascript"](code/javascript/bogo.js)
{% sample lang="py" %}
[import:4-12, lang:"python"](code/python/bogo.py)
[import:10-12, lang:"python"](code/python/bogo.py)
{% sample lang="hs" %}
[import:17-20, lang:"haskell"](code/haskell/bogoSort.hs)
{% sample lang="m" %}
[import:21-28, lang:"matlab"](code/matlab/bogosort.m)
{% sample lang="cpp" %}
[import:33-38, lang:"c_cpp"](code/c++/bogosort.cpp)
{% sample lang="rs" %}
[import:16-20, lang:"rust"](code/rust/bogosort.rs)
{% sample lang="swift" %}
[import:32-39, lang:"swift"](code/swift/bogosort.swift)
{% endmethod %}

That's it.
Ship it!
We are done here!

## Example Code

{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/bogo.jl)
{% sample lang="cs" %}
BogoSort.cs
[import, lang:"csharp"](code/csharp/BogoSort.cs)
Program.cs
[import, lang:"csharp"](code/csharp/Program.cs)
{% sample lang="clj" %}
[import, lang:"clojure"](code/clojure/bogo.clj)
{% sample lang="c" %}
[import, lang:"c_cpp"](code/c/bogo_sort.c)
{% sample lang="java" %}
[import, lang:"java"](code/java/bogo.java)
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/bogo.js)
{% sample lang="py" %}
[import, lang:"python"](code/python/bogo.py)
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/bogoSort.hs)
{% sample lang="m" %}
Expand All @@ -39,10 +75,6 @@ In code, it looks something like this:
[import, lang:"swift"](code/swift/bogosort.swift)
{% endmethod %}

That's it.
Ship it!
We are done here!


<script>
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
Expand Down
2 changes: 0 additions & 2 deletions contents/bogo_sort/code/java/bogo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
public class Bogo {
// The shuffle() function can be found in code/java/bogo.java
static void bogoSort(int[] arr) {
while(!isSorted(arr)) {
shuffle(arr);
Expand All @@ -26,7 +25,6 @@ static void shuffle(int[] arr) {
}


// main function (for testing)
public static void main(String[] args) {
int[] test = new int[]{20, -3, 50, 1, -6, 59};

Expand Down
1 change: 0 additions & 1 deletion contents/bogo_sort/code/javascript/bogo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function isSorted(arr) {
return true;
}

// The shuffle() function can be found in code/javascript/bogo.js
function bogoSort(arr) {
while (!isSorted(arr)) {
shuffle(arr);
Expand Down
47 changes: 42 additions & 5 deletions contents/bubble_sort/bubble_sort.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
{% sample lang="cs" %}
[import:9-27, lang:"csharp"](code/csharp/BubbleSort.cs)
{% sample lang="c" %}
[import:11-21, lang:"c_cpp"](code/c/bubble_sort.c)
[import:10-20, lang:"c_cpp"](code/c/bubble_sort.c)
{% sample lang="java" %}
[import:2-12, lang:"java"](code/java/bubble.java)
{% sample lang="js" %}
Expand All @@ -25,17 +25,17 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/bubbleSort.hs)
{% sample lang="cpp" %}
[import, lang:"c_cpp"](code/c++/bubblesort.cpp)
[import:33-56, lang:"c_cpp"](code/c++/bubblesort.cpp)
{% sample lang="rs" %}
[import:6-19, lang:"rust"](code/rust/bubble_sort.rs)
[import:6-16, lang:"rust"](code/rust/bubble_sort.rs)
{% sample lang="d" %}
[import:3-18, lang:"d"](code/d/bubble_sort.d)
{% sample lang="go" %}
[import:7-21, lang:"golang"](code/go/bubbleSort.go)
{% sample lang="racket" %}
[import:5-19, lang:"racket"](code/racket/bubbleSort.rkt)
[import:6-19, lang:"racket"](code/racket/bubbleSort.rkt)
{% sample lang="swift" %}
[import, lang:"swift"](code/swift/bubblesort.swift)
[import:1-12, lang:"swift"](code/swift/bubblesort.swift)
{% sample lang="ti83b" %}
[import:2-13, lang:"ti-83_basic"](code/ti83basic/BUBLSORT.txt)
{% endmethod %}
Expand All @@ -45,6 +45,43 @@ Now, as you might imagine, computer scientists have optimized this to the fiery
For now, it's fine to just bask in the simplicity that is bubble sort.
Trust me, there are plenty of more complicated algorithms that do precisely the same thing, only much, much better (for most cases).

## Example Code

{% method %}
{% sample lang="jl" %}
[import, lang:"julia"](code/julia/bubble.jl)
{% sample lang="cs" %}
BubbleSort.cs
[import, lang:"csharp"](code/csharp/BubbleSort.cs)
Program.cs
[import, lang:"csharp"](code/csharp/Program.cs)
{% sample lang="c" %}
[import, lang:"c_cpp"](code/c/bubble_sort.c)
{% sample lang="java" %}
[import, lang:"java"](code/java/bubble.java)
{% sample lang="js" %}
[import, lang:"javascript"](code/javascript/bubble.js)
{% sample lang="py" %}
[import, lang:"python"](code/python/bubblesort.py)
{% sample lang="m" %}
[import, lang:"matlab"](code/matlab/bubblesort.m)
{% sample lang="hs" %}
[import, lang:"haskell"](code/haskell/bubbleSort.hs)
{% sample lang="cpp" %}
[import, lang:"c_cpp"](code/c++/bubblesort.cpp)
{% sample lang="rs" %}
[import, lang:"rust"](code/rust/bubble_sort.rs)
{% sample lang="d" %}
[import, lang:"d"](code/d/bubble_sort.d)
{% sample lang="go" %}
[import, lang:"golang"](code/go/bubbleSort.go)
{% sample lang="racket" %}
[import, lang:"racket"](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)
{% endmethod %}

<script>
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
Expand Down
1 change: 0 additions & 1 deletion contents/bubble_sort/code/java/bubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ static void bubbleSort(int[] arr) {
}


// main function (for testing)
public static void main(String[] args) {
int[] test = new int[]{20, -3, 50, 1, -6, 59};

Expand Down