30 lines
494 B
Rust
30 lines
494 B
Rust
|
use std::rc::Rc;
|
||
|
|
||
|
pub struct List<T> {
|
||
|
head: Option<Rc<Node<T>>>,
|
||
|
}
|
||
|
|
||
|
pub struct Node<T> {
|
||
|
data: T,
|
||
|
parent: Option<Rc<Node<T>>>,
|
||
|
}
|
||
|
|
||
|
impl<T> List<T> {
|
||
|
pub fn new() -> Self {
|
||
|
List { head: None }
|
||
|
}
|
||
|
|
||
|
pub fn push_front(&self, data: T) -> List<T> {
|
||
|
List {
|
||
|
head: Some(Rc::new(Node {
|
||
|
data: data,
|
||
|
parent: self.head.clone(),
|
||
|
})),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn get_data(&self) -> &T {
|
||
|
&self.data
|
||
|
}
|
||
|
}
|