pub fn clone_tree(node: &NodePtr<T>) -> NodePtr<T> {
        let root = Tree::new(node.borrow().data.clone());
        root.borrow_mut().parent = node.borrow().parent.clone();
        let mut stack = node.borrow().siblings.clone();
        stack.reverse();
        let mut new_stack = vec![];
        let mut depth_stack = vec![];

        while let Some(current) = stack.pop() {
            let current = current.borrow();
            if !current.siblings.is_empty() {
                new_stack.push(Tree::push_child(
                    new_stack.last().unwrap_or(&root),
                    current.data.clone(),
                ));
                let mut siblings = current.siblings.clone();
                depth_stack.push(siblings.len() - 1);
                siblings.reverse();
                stack.extend_from_slice(&siblings);
            } else {
                Tree::push_child(new_stack.last().unwrap_or(&root), current.data.clone());
                while let Some(depth) = depth_stack.last_mut() {
                    if *depth == 0 {
                        depth_stack.pop();
                        new_stack.pop();
                    } else {
                        *depth -= 1;
                        break;
                    }
                }
            }
        }

        root
    }
/// Clone tree
///
/// Creates copy of tree that uses the same layout, with the same
/// data, but different set of pointers to the heap.
///
/// # Examples
///
/// ```
/// let root = Tree::new(0);
/// Tree::push_child(&root, 1);
/// Tree::push_child(&root, 2);
///
/// let new = Tree::clone_tree(&root);
/// assert_eq!(root, new);
/// ```
///
Clone tree
Creates copy of tree that uses the same layout, with the same
data, but different set of pointers to the heap.
Clone tree Creates copy of tree that uses the same layout with the same data but different set of pointers to the heap .
pub fn clone_tree(node: &NodePtr<T>) -> NodePtr<T> {
        let root = Tree::new(node.borrow().data.clone());
        root.borrow_mut().parent = node.borrow().parent.clone();
        let mut stack = node.borrow().siblings.clone();
        stack.reverse();
        let mut new_stack = vec![];
        let mut depth_stack = vec![];
        while let Some(current) = stack.pop() {
            let current = current.borrow();
            if !current.siblings.is_empty() {
                new_stack.push(Tree::push_child(
                    new_stack.last().unwrap_or(&root),
                    current.data.clone(),
                ));
                let mut siblings = current.siblings.clone();
                depth_stack.push(siblings.len() - 1);
                siblings.reverse();
                stack.extend_from_slice(&siblings);
            } else {
                Tree::push_child(new_stack.last().unwrap_or(&root), current.data.clone());
                while let Some(depth) = depth_stack.last_mut() {
                    if *depth == 0 {
                        depth_stack.pop();
                        new_stack.pop();
                    } else {
                        *depth -= 1;
                        break;
                    }
                }
            }
        }
        root
    }
pub fn clone_tree ( node : & NodePtr < T > ) -> NodePtr < T > { let root = Tree :: new ( node . borrow ( ) . data . clone ( ) ) ; root . borrow_mut ( ) . parent = node . borrow ( ) . parent . clone ( ) ; let mut stack = node . borrow ( ) . siblings . clone ( ) ; stack . reverse ( ) ; let mut new_stack = vec ! [ ] ; let mut depth_stack = vec ! [ ] ; while let Some ( current ) = stack . pop ( ) { let current = current . borrow ( ) ; if ! current . siblings . is_empty ( ) { new_stack . push ( Tree :: push_child ( new_stack . last ( ) . unwrap_or ( & root ) , current . data . clone ( ) , ) ) ; let mut siblings = current . siblings . clone ( ) ; depth_stack . push ( siblings . len ( ) - 1 ) ; siblings . reverse ( ) ; stack . extend_from_slice ( & siblings ) ; } else { Tree :: push_child ( new_stack . last ( ) . unwrap_or ( & root ) , current . data . clone ( ) ) ; while let Some ( depth ) = depth_stack . last_mut ( ) { if * depth == 0 { depth_stack . pop ( ) ; new_stack . pop ( ) ; } else { * depth -= 1 ; break ; } } } } root }
Clone tree
Creates copy of tree that uses the same layout, with the same
data, but different set of pointers to the heap.
Clone tree Creates copy of tree that uses the same layout with the same data but different set of pointers to the heap .
node
&NodePtr<T>
examples


let new = Tree::clone_tree(&root);
assert_eq!(root, new);
```
let new = Tree :: clone_tree ( &root ) ; assert_eq! ( root new ) ; ` ` `