Skip to content
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

Adding elementary sorting algorithms #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions algorithms/sorting/bubblesort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bubblesort(list) :=
block(
[len: length(list)],
for i:1 thru len do (
for j:1 thru (len - 1) do (
if (list[j] > list[j + 1]) then (
temp:list[j],
list[j]:list[j + 1],
list[j + 1]:temp
)
)
),
list
);
14 changes: 14 additions & 0 deletions algorithms/sorting/insertionsort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
insertionnsort(list) :=
block(
[len: length(list)],
for i:2 thru len do (
key:list[i],
j:(i - 1),
while j >= 1 and list[j] > key do (
list[j + 1]:list[j],
j:(j - 1)
),
list[j + 1]:key
),
list
);
14 changes: 14 additions & 0 deletions algorithms/sorting/selectionsort.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
selectionnsort(list) :=
block(
[len: length(list)],
for i:1 thru len do (
min:i,
for j:(i + 1) thru len do (
if (list[j] < list[min]) then min:j
),
temp:list[min],
list[min]:list[i],
list[i]:temp
),
list
);
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ just a paper and pencil.

- [Bead Sort](sorting/)
- [Bogo Sort](sorting/)
- [Bubble Sort](sorting/)
- [Bubble Sort](algorithms/sorting/bubblesort.m)
- [Bucket Sort](sorting/)
- [Circle Sort](sorting/)
- [Comb Sort](sorting/)
Expand All @@ -343,14 +343,14 @@ just a paper and pencil.
- [Flash Sort](sorting/)
- [Gnome Sort](sorting/)
- [Heap Sort](sorting/)
- [Insertion Sort](sorting/)
- [Insertion Sort](algorithms/sorting/insertionsort.m)
- [Intro Sort](sorting/)
- [Median Sort](sorting/)
- [Merge Sort](sorting/)
- [Merge Sort](algorithms/sorting/mergesort.m)
- [Pipeonhole Sort](sorting/)
- [Quick Sort](sorting/)
- [Radix Sort](sorting/)
- [Selection Sort](sorting/)
- [Selection Sort](algorithms/sorting/selectionsort.m)
- [Shaker Sort](sorting/)
- [Shell Sort](sorting/)
- [Sleep Sort](sorting/)
Expand Down