-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
221e901
commit 2b218a2
Showing
30 changed files
with
227 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
pub fn linear_search(s: []int, i: int): (pos: int) { | ||
for j, x in s { | ||
if x == i { | ||
ret j | ||
} | ||
} | ||
ret -1 | ||
for j, x in s { | ||
if x == i { | ||
ret j | ||
} | ||
} | ||
ret -1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
pub fn bubble_sort(mut s: []int): []int { | ||
let mut swapped = true | ||
for swapped { | ||
swapped = false | ||
let mut i = 0 | ||
for i < s.len-1; i++ { | ||
if s[i+1] < s[i] { | ||
s[i+1], s[i] = s[i], s[i+1] | ||
swapped = true | ||
} | ||
} | ||
} | ||
let mut swapped = true | ||
for swapped { | ||
swapped = false | ||
let mut i = 0 | ||
for i < s.len-1; i++ { | ||
if s[i+1] < s[i] { | ||
s[i+1], s[i] = s[i], s[i+1] | ||
swapped = true | ||
} | ||
} | ||
} | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
pub fn exchange_sort(mut s: []int): []int { | ||
let mut i = 0 | ||
for i < s.len-1; i++ { | ||
let mut j = i + 1 | ||
for j < s.len; j++ { | ||
if s[i] > s[j] { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
} | ||
} | ||
let mut i = 0 | ||
for i < s.len-1; i++ { | ||
let mut j = i + 1 | ||
for j < s.len; j++ { | ||
if s[i] > s[j] { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
} | ||
} | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
pub fn insertion_sort(mut s: []int): []int { | ||
let mut current_index = 1 | ||
for current_index < s.len; current_index++ { | ||
let temporary = s[current_index] | ||
let mut iterator = current_index | ||
for iterator > 0 && s[iterator-1] > temporary; iterator-- { | ||
s[iterator] = s[iterator-1] | ||
} | ||
s[iterator] = temporary | ||
} | ||
let mut current_index = 1 | ||
for current_index < s.len; current_index++ { | ||
let temporary = s[current_index] | ||
let mut iterator = current_index | ||
for iterator > 0 && s[iterator-1] > temporary; iterator-- { | ||
s[iterator] = s[iterator-1] | ||
} | ||
s[iterator] = temporary | ||
} | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
pub fn quick_sort(mut s: []int): []int { | ||
if s.len <= 1 { | ||
ret s | ||
} | ||
if s.len <= 1 { | ||
ret s | ||
} | ||
|
||
let mut i = -1 | ||
let last = s[s.len-1] | ||
for j in s { | ||
if s[j] <= last { | ||
i++ | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
} | ||
let mut i = -1 | ||
let last = s[s.len-1] | ||
for j in s { | ||
if s[j] <= last { | ||
i++ | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
} | ||
|
||
quick_sort(s[:i]) | ||
quick_sort(s[i+1:]) | ||
quick_sort(s[:i]) | ||
quick_sort(s[i+1:]) | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
pub fn selection_sort(mut s: []int): []int { | ||
let mut i = 0 | ||
for i < s.len; i++ { | ||
let mut min = i | ||
let mut j = i + 1 | ||
for j < s.len; j++ { | ||
if s[j] < s[min] { | ||
min = j | ||
} | ||
} | ||
let mut i = 0 | ||
for i < s.len; i++ { | ||
let mut min = i | ||
let mut j = i + 1 | ||
for j < s.len; j++ { | ||
if s[j] < s[min] { | ||
min = j | ||
} | ||
} | ||
|
||
s[i], s[min] = s[min], s[i] | ||
} | ||
s[i], s[min] = s[min], s[i] | ||
} | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
pub fn shell_sort(mut s: []int): []int { | ||
let mut d = int(s.len / 2) | ||
for d > 0; d /= 2 { | ||
let mut i = d | ||
for i < s.len; i++ { | ||
let mut j = i | ||
for j >= d && s[j-d] > s[j]; j -= d { | ||
s[j], s[j-d] = s[j-d], s[j] | ||
} | ||
} | ||
} | ||
let mut d = int(s.len / 2) | ||
for d > 0; d /= 2 { | ||
let mut i = d | ||
for i < s.len; i++ { | ||
let mut j = i | ||
for j >= d && s[j-d] > s[j]; j -= d { | ||
s[j], s[j-d] = s[j-d], s[j] | ||
} | ||
} | ||
} | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
pub fn simple_sort(mut s: []int): []int { | ||
let mut i = 1 | ||
for i < s.len; i++ { | ||
let mut j = 0 | ||
for j < s.len-1; j++ { | ||
if s[i] < s[j] { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
} | ||
} | ||
let mut i = 1 | ||
for i < s.len; i++ { | ||
let mut j = 0 | ||
for j < s.len-1; j++ { | ||
if s[i] < s[j] { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
} | ||
} | ||
|
||
ret s | ||
ret s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use tests::{TestStack} | ||
|
||
pub fn math_package_tests(mut &tests: TestStack) { | ||
abs_tests(tests) | ||
median_tests(tests) | ||
abs_tests(tests) | ||
median_tests(tests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use tests::{TestStack} | ||
|
||
pub fn search_package_tests(mut &tests: TestStack) { | ||
linear_search_tests(tests) | ||
linear_search_tests(tests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
use tests::{TestStack} | ||
|
||
pub fn sort_package_tests(mut &tests: TestStack) { | ||
bubble_sort_tests(tests) | ||
exchange_sort_tests(tests) | ||
insertion_sort_tests(tests) | ||
quick_sort_tests(tests) | ||
selection_sort_tests(tests) | ||
shell_sort_tests(tests) | ||
simple_sort_tests(tests) | ||
bubble_sort_tests(tests) | ||
exchange_sort_tests(tests) | ||
insertion_sort_tests(tests) | ||
quick_sort_tests(tests) | ||
selection_sort_tests(tests) | ||
shell_sort_tests(tests) | ||
simple_sort_tests(tests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.