首先定义一个链表式的数据结构来存储图的顶点信息
//define a Linked_List
use std::rc::Rc;
use std::cell::RefCell;
pub type Link = Option<Rc<RefCell<Node>>>;
pub struct Node{
pub x:usize,
pub next: Link,
}
impl Node{
pub fn new(x:usize) -> Self{
Self{
x,
next:None,
}
}
}
pub struct GraphLink{
pub first : Link,
pub last : Link,
}
impl GraphLink{
pub fn new() -> Self{
Self{
first:None,
last:None,
}
}
pub fn is_emtpy(&self) -> bool{
return self.first.is_none();
}
pub fn print_node(&self){
let mut current = self.first.clone();
while let Some(value) = current{
print!("[{}]",value.borrow().x);
current = value.borrow().next.clone();
}
}
pub fn get_first(&self) -> Link{
return self.first.clone();
}
pub fn insert(&mut self,x:usize){