Skip to content

Commit 478316c

Browse files
authored
Merge pull request kelvins#66 from heitor582/main
[rust] Adiciona algoritmo de ordenação insertion_sort
2 parents 4b5f35d + 7341e7c commit 478316c

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Com o objetivo de alcançar uma abrangência maior e encorajar novas pessoas a c
5656
| [Counting Sort][39] | C/C++ | Java | Python | [Go](./src/go/countingsort/countingsort.go) | [Ruby](./src/ruby/count_sort.rb) | JS | Pascal | Swift | Rust |
5757
| [Gnome Sort][40] | C/C++ | Java | Python | [Go](./src/go/gnomesort/gnomesort.go) | Ruby | JS | Pascal | Swift | Rust |
5858
| [Heapsort][41] | C/C++ | [Java](./src/java/HeapSort.java) | Python | [Go](./src/go/heapsort/heapsort.go) | [Ruby](./src/ruby/heap_sort.rb) | [JS](./src/javascript/HeapSort.js) | [Pascal](./src/pascal/heapsort.pas) | Swift | Rust |
59-
| [Insertion Sort][42] | [C/C++](./src/c/InsertionSort.cpp) | [Java](./src/java/InsertionSort.java) | [Python](./src/python/insertion_sort.py) | [Go](./src/go/insertionsort/insertionsort.go) | [Ruby](./src/ruby/insertion_sort.rb) | [JS](./src/javascript/InsertionSort.js) | Pascal | Swift | Rust |
59+
| [Insertion Sort][42] | [C/C++](./src/c/InsertionSort.cpp) | [Java](./src/java/InsertionSort.java) | [Python](./src/python/insertion_sort.py) | [Go](./src/go/insertionsort/insertionsort.go) | [Ruby](./src/ruby/insertion_sort.rb) | [JS](./src/javascript/InsertionSort.js) | Pascal | Swift | [Rust](./src/rust/insertion_sort.rs) |
6060
| [Merge Sort][44] | [C/C++](./src/c/MergeSort.c) | [Java](./src/java/Mergesort.java) | Python | [Go](./src/go/mergesort/mergesort.go) | [Ruby](./src/ruby/merge_sort.rb) | [JS](./src/javascript/MergeSort.js) | [Pascal](./src/pascal/mergesort.pas) | Swift | Rust |
6161
| [Quicksort][45] | [C/C++](./src/c/QuickSort.cpp) | [Java](./src/java/Quicksort.java) | [Python](./src/python/quick_sort.py) | [Go](./src/go/quicksort/quicksort.go) | [Ruby](./src/ruby/quick_sort.rb) | [JS](./src/javascript/QuickSort.js) | Pascal | Swift | Rust |
6262
| [Radix Sort][46] | C/C++ | [Java](./src/java/RadixSort.java) | Python | [Go](./src/go/radixsort/radixsort.go) | [Ruby](./src/ruby/radix_sort.rb) | [JS](./src/javascript/RadixSort.js) | Pascal | Swift | Rust |

src/rust/insertion_sort.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main(){
2+
println!{"{:?}", insertion_sort(vec![54,42,11,33,24,99,77,80])};
3+
}
4+
fn insertion_sort(mut vetor: Vec<i32>) -> Vec<i32> {
5+
for i in 1..vetor.len() {
6+
let mut index: i32 = i as i32;
7+
while index > 0 && vetor[index as usize] < vetor[index as usize - 1] {
8+
vetor.swap(index as usize, index as usize - 1);
9+
index -= 1;
10+
}
11+
}
12+
vetor
13+
}

src/rust/palindromo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() {
77
println!("{:?}", palindromo("Was it a palindrome?".to_string()));
88
println!("{:?}", palindromo("No lemon, no melon".to_string()));
99
}
10-
pub fn palindromo(mut word: String) -> bool {
10+
fn palindromo(mut word: String) -> bool {
1111
word = word.to_lowercase().split_whitespace().collect::<String>();
1212
let reversed_string: String = word.chars().rev().collect::<String>();
1313
if word.len() <= 1 {

0 commit comments

Comments
 (0)