38 lines
834 B
Plaintext
38 lines
834 B
Plaintext
|
---
|
||
|
title: "Rust I"
|
||
|
date: "2020.03.04"
|
||
|
slug: "posts/rust-i"
|
||
|
archive: true
|
||
|
---
|
||
|
|
||
|
|
||
|
so i tried to implement insertion sort using rust, why ? im bored but i find something interesting stuff
|
||
|
|
||
|
```rs
|
||
|
let mut arr = [5,3,2,4,1,6];
|
||
|
for n in 1..arr.len() {
|
||
|
let key = arr[n];
|
||
|
let mut i = n - 1;
|
||
|
while i >= 0 && arr[i] > key {
|
||
|
arr[(i+1)] = arr[i];
|
||
|
i -= 1;
|
||
|
}
|
||
|
arr[(i+1)] = key;
|
||
|
}
|
||
|
println!('{:?}', arr);
|
||
|
```
|
||
|
|
||
|
it's basic stuff no sugarcoated , buuuut it failed of course it and the compiler said
|
||
|
```
|
||
|
warning: comparison is useless due to type limits
|
||
|
--> insertion_sort.rs:26:11
|
||
|
|
|
||
|
26 | while i >= 0 && arr2[i] > key {
|
||
|
| ^^^^^^
|
||
|
|
|
||
|
= note: `#[warn(unused_comparisons)]` on by default
|
||
|
```
|
||
|
|
||
|
well my lil snailass brain thought "unused comparison??!! what ?
|
||
|
|