Complete the code to define a graph vertex as a struct with a name field.
struct Vertex {
name: String,
edges: Vec<[1]>,
}The edges field stores a list of Edge structs connected to this vertex.
Complete the code to create a directed edge from source to target vertex.
struct Edge {
target: usize,
weight: i32,
directed: [1],
}Setting directed to true means the edge points from source to target only.
Fix the error in the code to add an undirected edge with weight 5.
let edge = Edge {
target: 2,
weight: [1],
directed: [2],
};Weight should be 5 and directed false for an undirected edge.
Fill both blanks to create a weighted undirected edge from vertex 1 to vertex 3 with weight 7.
let edge = Edge {
target: [1],
weight: [2],
directed: false,
};Target vertex is 3 and weight is 7 for this edge.
Fill all three blanks to create a graph with two vertices and one directed weighted edge from vertex 0 to vertex 1 with weight 10.
let vertices = vec![
Vertex { name: String::from("A"), edges: vec![Edge { target: [1], weight: [2], directed: [3] }] },
Vertex { name: String::from("B"), edges: vec![] },
];The edge goes to vertex 1, has weight 10, and is directed (true).
