backing out of linked lists

This commit is contained in:
specCon18 2024-05-19 05:08:10 -04:00
parent e86e09739e
commit 74d3013a2e

View file

@ -222,50 +222,3 @@ impl<T> Stack<T> {
self.stack.last()
}
}
struct Node<T> {
value: T,
prev: Option<Box<Node<T>>>,
next: Option<Box<Node<T>>>,
}
type Link<T> = Option<Box<Node<T>>>;
pub struct List<T> {
head: Link<T>,
tail: Link<T>
}
impl<T> List<T> {
pub fn new() -> Self {
List { head: None, tail: None }
}
// Access node by index
pub fn get_node(&self, index: usize) -> Option<&Node<T>> {
let mut current_node = self.head.as_ref().map(|boxed_node| &**boxed_node);
let mut current_index = 0;
while let Some(node) = current_node {
if current_index == index {
return Some(node);
}
current_node = node.next.as_ref().map(|boxed_node| &**boxed_node);
current_index += 1;
}
None
}
pub fn insert_before(insertion_node:Node<T>,node:Node<T>) -> Self {
//TODO: Implement Insert Before
List{head:None,tail:None}
}
pub fn insert_after(insertion_node:Node<T>,node:Node<T>) -> Self {
//TODO: Implement Insert After
List{head:None,tail:None}
}
pub fn delete(&self,index:usize) -> Self {
//TODO: Implement Delete
List{head:None,tail:None}
}
}