Skip to content

Commit 4ab6d7e

Browse files
committed
[rust] adiciona algoritmo de Ordenação insertion_sort
1 parent 4b5f35d commit 4ab6d7e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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!{"{:?}", algoritmo_ordenacao::insertion_sort::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)