[Solved] ECE421 Assignment 5 Refactoring
5.0
1 customer review
Digital download
Digital download
$25.00
Message us on WhatsApp for payment or download support.
| } | pub struct L{x: usize,y: usize,pub fn foo (text: &str, string: &str)->Vec<L> let mut r= Vec::new(); let mut x=0;for line in text.lines(){for (y, _) in line.match_indices(string){r.push(L{x : x, y: y,}) | { |
| } | } x+=1; } r |
| let results = foo(Shall I compare thee to a summers day?Thou art more lovely and more temperate:Rough winds do shake the darling buds of May, And summers lease hath all too short a date:Sometimes too hot the eye of heaven shines, And too often is his gold complexion dimmd:And every fair from fair sometimes declines,By chance or natures changing course untrimmd;By thy eternal summer shall not fade,Nor lose possession of that fair thou owest;Nor shall Death brag thou wanderst in his shade,When in eternal lines to time thou growest:So long as men can breathe or eyes can see,So long lives this and this gives life to thee., the); for x in results {println!(x : {}, y : {}, x.x, x.y);} |
| use std::collections::HashMap; #[derive(Debug)] struct TrieNode {chs: HashMap<char, TrieNode>, value: Option<i32>,} #[derive(Debug)] struct Trie { root: TrieNode,}impl Trie {fn new() -> Trie { Trie {root: TrieNode { chs: HashMap::new(), value: None,},}}fn add_string(&mut self, string: String, value: i32) { let mut current_node = &mut self.root; for c in string.chars() {current_node = current_node.chs.entry(c).or_insert(TrieNode { chs: HashMap::new(), value: None,});}current_node.value = Some(value);}}fn main() {let mut trie = Trie::new(); trie.add_string(B.to_string(), 1); trie.add_string(Bar.to_string(), 2); println!({:#?}, trie);} |