Doubly Linked List implementation in progress

This commit is contained in:
Víctor Martínez 2020-12-05 21:50:09 +01:00
parent 971e712f97
commit 9ea26de7ac
2 changed files with 31 additions and 7 deletions

View file

@ -1,7 +1 @@
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}
pub mod linked_list;

30
src/linked_list.rs Normal file
View file

@ -0,0 +1,30 @@
use std::rc::Rc;
enum Node<T> {
Header {
first: Option<Rc<Node<T>>>,
last: Option<Rc<Node<T>>>,
},
Child {
elem: T,
next: Rc<Node<T>>,
prev: Rc<Node<T>>,
},
}
pub struct DoublyLinkedList<T> {
length: u64,
root: Node<T>,
}
impl<T> DoublyLinkedList<T> {
pub fn new() -> Self {
DoublyLinkedList {
length: 0,
root: Node::Header {
first: None,
last: None,
},
}
}
}