mirror of
https://codeberg.org/JasterV/cool-data-structures.git
synced 2026-04-26 18:40:04 +00:00
Doubly Linked List implementation in progress
This commit is contained in:
parent
971e712f97
commit
9ea26de7ac
2 changed files with 31 additions and 7 deletions
|
|
@ -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
30
src/linked_list.rs
Normal 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,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue