Created
October 15, 2019 12:53
-
-
Save stmtk1/f674cf2ca81042d5e0c4851c58accd77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cell::RefCell; | |
use std::rc::Rc; | |
use std::collections::LinkedList; | |
#[derive(Debug, Clone)] | |
struct VueGraph { | |
parent: Vec<Rc<RefCell<VueGraph>>>, | |
name: String, | |
children: Vec<Rc<RefCell<VueGraph>>>, | |
} | |
impl VueGraph { | |
fn new(name: String) -> VueGraph { | |
let vue_graph = VueGraph { | |
parent: Vec::new(), | |
name: name.clone(), | |
children: Vec::new(), | |
}; | |
vue_graph | |
} | |
fn add_parent(&mut self, parent: &VueGraph){ | |
self.parent.push(Rc::new(RefCell::new(parent.clone()))); | |
} | |
fn add_child(&mut self, parent: &VueGraph){ | |
self.children.push(Rc::new(RefCell::new(parent.clone()))); | |
} | |
fn search(&self) -> LinkedList<VueGraph> { | |
let ret: LinkedList<VueGraph> = LinkedList::new(); | |
println!("{}", self.name); | |
for child in &self.children { | |
let child = (**child).clone().into_inner().search(); | |
} | |
ret | |
} | |
} | |
fn main() { | |
let mut graph = VueGraph::new(String::from("a")); | |
let parent =VueGraph::new(String::from("b")); | |
let child =VueGraph::new(String::from("c")); | |
graph.add_parent(&parent); | |
graph.add_child(&child); | |
graph.search(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment