mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 03:16:29 +08:00
c3add62dc7
* feat: add rust codes for graph chapter * update: remove Vertex and it's method to vertex.rs
21 lines
No EOL
527 B
Rust
21 lines
No EOL
527 B
Rust
/*
|
|
* File: vertex.rs
|
|
* Created Time: 2023-07-13
|
|
* Author: night-cruise (2586447362@qq.com)
|
|
*/
|
|
|
|
/* 顶点类型 */
|
|
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
|
|
pub struct Vertex {
|
|
pub val: i32
|
|
}
|
|
|
|
/* 输入值列表 vals ,返回顶点列表 vets */
|
|
pub fn vals_to_vets(vals: Vec<i32>) -> Vec<Vertex> {
|
|
vals.into_iter().map(|val| Vertex { val }).collect()
|
|
}
|
|
|
|
/* 输入顶点列表 vets ,返回值列表 vals */
|
|
pub fn vets_to_vals(vets: Vec<Vertex>) -> Vec<i32> {
|
|
vets.into_iter().map(|vet| vet.val).collect()
|
|
} |