Struct BinTree

Source
pub struct BinTree<T: PartialEq> { /* private fields */ }
Expand description

The BinTree struct contains operations specific to binary trees.

NOTE: Requires the PartialEq trait bounds for binary tree operations

Implementations§

Source§

impl<T> BinTree<T>
where T: PartialEq,

Source

pub fn new() -> BinTree<T>

Creates a new generic binary tree.

Source

pub fn add_left(&mut self, ancestor: Node<T>, node: Box<Node<T>>)

Adds a left node to a parent

Source

pub fn add_right(&mut self, ancestor: Node<T>, node: Box<Node<T>>)

Adds a right node to a parent

Source

pub fn set(&mut self, _p: Node<T>, _node: T) -> Result<(), String>

Overwrites the data at a given node (position) */

WARNING: Unimplmented

Source

pub fn attach(&mut self, _left: Node<T>, _right: Node<T>)

WARNING: Unimplmented

Source

pub fn remove(&mut self, p: Node<T>)

WARNING: Unimplmented

Source

pub fn size(&self) -> usize

Returns the number of nodes in the tree

Source

pub fn is_empty(&self) -> bool

Returns true if the tree contains no nodes

Source

pub fn root(&self) -> Option<&Box<Node<T>>>

Returns an immutable reference to the root of the tree

Trait Implementations§

Source§

impl<T> BinaryTree<T> for BinTree<T>
where T: Clone + PartialEq,

Source§

type Position = Box<Node<T>>

Source§

fn left(&self, node: Self::Position) -> Option<Self::Position>

Returns the position of the left child of a given node
Source§

fn right(&self, node: Self::Position) -> Option<Self::Position>

Returns the position of the right child of a given node
Source§

fn sibling(&self, node: Self::Position) -> Option<Self::Position>

Returns the position of the sibling of a given node
Source§

impl<T> Default for BinTree<T>
where T: PartialEq,

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Tree<T> for BinTree<T>
where T: Clone + PartialEq,

Source§

fn get<'a>(&'a self, node: &'a Self::Position) -> Option<&'a T>

Returns an immutable reference to the node’s data

Source§

fn parent(&self, node: Self::Position) -> Option<Self::Position>

Returns an immutable reference to the parent of the given node

Source§

fn num_children(&self, node: Self::Position) -> Option<usize>

Returns the number of children for a given node

Source§

fn children(&self, node: Self::Position) -> Option<Vec<Self::Position>>

Returns a collection of the node’s children

Source§

fn is_leaf(&self, node: Self::Position) -> bool

Returns true if the provided node has no children

Source§

fn is_root(&self, node: Self::Position) -> bool

Returns true if the node is the root

Source§

fn depth(&self, node: Self::Position) -> Option<usize>

Depth…

Source§

fn height(&self, node: Self::Position) -> Option<usize>

Height…

Source§

type Position = Box<Node<T>>

Auto Trait Implementations§

§

impl<T> Freeze for BinTree<T>

§

impl<T> RefUnwindSafe for BinTree<T>
where T: RefUnwindSafe,

§

impl<T> Send for BinTree<T>
where T: Send,

§

impl<T> Sync for BinTree<T>
where T: Sync,

§

impl<T> Unpin for BinTree<T>

§

impl<T> UnwindSafe for BinTree<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V