pub struct Node<T: Ord> { /* private fields */ }Implementations§
Source§impl<T> Node<T>
impl<T> Node<T>
Sourcepub fn new(data: T) -> Box<Self>
pub fn new(data: T) -> Box<Self>
use crate::bst::bst;
let one = bst::Node::new(1);
assert_eq!(*one.get_data(), 1);pub fn get_data(&self) -> &T
pub fn set_data(&mut self, data: T)
Sourcepub fn get_left(&self) -> &Option<Box<Node<T>>>
pub fn get_left(&self) -> &Option<Box<Node<T>>>
use crate::bst::bst;
use crate::bst::bst::Node;
let two = bst::Node::new(2);
let mut one = bst::Node::new(1);
one.set_left(Some(two));
let one = one;
assert_eq!(
one
.get_left()
.as_ref()
.map(|node| node.get_data().clone())
.unwrap(),
2
);pub fn set_left(&mut self, left: Option<Box<Node<T>>>)
Sourcepub fn get_right(&self) -> &Option<Box<Node<T>>>
pub fn get_right(&self) -> &Option<Box<Node<T>>>
use crate::bst::bst;
use crate::bst::bst::Node;
let two = bst::Node::new(2);
let mut one = bst::Node::new(1);
one.set_right(Some(two));
let one = one;
assert_eq!(
one
.get_right()
.as_ref()
.map(|node| node.get_data().clone())
.unwrap(),
2
);pub fn set_right(&mut self, right: Option<Box<Node<T>>>)
Trait Implementations§
Source§impl<T> Ord for Node<T>where
T: Ord,
impl<T> Ord for Node<T>where
T: Ord,
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
use crate::bst::bst;
let one = bst::Node::new(1);
let two = bst::Node::new(2);
let thr = bst::Node::new(3);
assert!(one < two);
assert!(thr > one);
assert!(one == one);1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T> PartialEq for Node<T>where
T: Ord,
impl<T> PartialEq for Node<T>where
T: Ord,
Source§impl<T> PartialOrd for Node<T>where
T: Ord,
impl<T> PartialOrd for Node<T>where
T: Ord,
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
use crate::bst::bst;
let one = bst::Node::new(1);
let two = bst::Node::new(2);
assert!(one < two);impl<T> Eq for Node<T>where
T: Ord,
Auto Trait Implementations§
impl<T> Freeze for Node<T>where
T: Freeze,
impl<T> RefUnwindSafe for Node<T>where
T: RefUnwindSafe,
impl<T> Send for Node<T>where
T: Send,
impl<T> Sync for Node<T>where
T: Sync,
impl<T> Unpin for Node<T>where
T: Unpin,
impl<T> UnwindSafe for Node<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more