1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::{DoublyLinkedList, ListNode};
impl<T> ListNode<T> {
/// Creates a new empty `ListNode`.
pub fn new(data: T) -> ListNode<T> {
ListNode {
data,
next: None,
prev: None,
}
}
}
impl<T> DoublyLinkedList<T> {
/// Creates a new empty `DoublyLinkedList`.
///
/// # Examples
/// ```
/// use villa01_data_structures::doubly_linked_list::DoublyLinkedList;
/// struct T;
/// let list:DoublyLinkedList<T> = DoublyLinkedList::new();
/// assert!(list.is_empty());
/// ````
pub fn new() -> DoublyLinkedList<T> {
DoublyLinkedList {
head: None,
tail: None,
length: 0,
}
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_new() {
let list: DoublyLinkedList<bool> = DoublyLinkedList::new();
assert!(list.is_empty())
}
}