
#[derive(Clone)]
pub struct NTreeNode<T>
{
    value: T,
    children: Vec<NTreeNode<T>>

}

impl<T> NTreeNode<T>
{
    pub fn new(val: T)
    -> Self
    {
        Self {
            value: val,
            children: vec![]
        }
    }
    
    pub fn value(&self) -> &T { &self.value }
    pub fn value_mut(&mut self) -> &mut T { &mut self.value }

    pub fn children(&self) -> &[NTreeNode<T>] { &self.children.as_slice() }

    pub fn insert_value(
        &mut self,
        val: T)
    {
        self.children.push(NTreeNode { value: val, children: vec![] });
    }

    pub fn insert_node(
        &mut self,
        subtree: NTreeNode<T>)
    {
        self.children.push(subtree);
    }

    pub fn traverse_preorder(&self)
    -> Vec<&T>
    {
        let mut result = vec![self.value()];
        for child in &self.children {
            result.extend(child.traverse_preorder().iter());
        }
        result
    }
}
