mirror of
https://github.com/xfarrow/lasd.git
synced 2025-06-05 21:49:14 +02:00
Library 3
binarytreevec
This commit is contained in:
15
librerie/exercise3/binarytree/lnk/binarytreelnk.cpp
Normal file → Executable file
15
librerie/exercise3/binarytree/lnk/binarytreelnk.cpp
Normal file → Executable file
@@ -34,20 +34,15 @@ bool BinaryTreeLnk<Data>::NodeLnk::HasRightChild() const noexcept{
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
NodeLnk& BinaryTreeLnk<Data>::NodeLnk::LeftChild() const{
|
||||
Node& BinaryTreeLnk<Data>::NodeLnk::LeftChild() const{
|
||||
return *left;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
NodeLnk& BinaryTreeLnk<Data>::NodeLnk::RightChild() const{
|
||||
Node& BinaryTreeLnk<Data>::NodeLnk::RightChild() const{
|
||||
return *right;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BinaryTreeLnk<Data>::BinaryTreeLnk(){
|
||||
size = 0;
|
||||
}
|
||||
|
||||
// creates a tree from a linear container in breadth
|
||||
template <typename Data>
|
||||
BinaryTreeLnk<Data>::BinaryTreeLnk(const LinearContainer<Data>& lc){
|
||||
@@ -85,15 +80,17 @@ BinaryTreeLnk<Data>::BinaryTreeLnk(const BinaryTreeLnk<Data>& tree){
|
||||
}
|
||||
|
||||
BinaryTreeLnk<Data>::NodeLnk* BinaryTreeLnk<Data>::CopyTree(struct BinaryTreeLnk<Data>::NodeLnk* nodeToCopy){
|
||||
if(nodeToCopy==nullptr) return nullptr;
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* tmp = CreateNode(nodeToCopy.Element());
|
||||
|
||||
if(nodeToCopy.HasLeftChild())
|
||||
tmp->left = copyTrees(&(nodeToCopy.LeftChild()));
|
||||
tmp->left = copyTree(&(nodeToCopy.LeftChild()));
|
||||
else
|
||||
tmp->left = nullptr;
|
||||
|
||||
if(nodeToCopy.HasRightChild())
|
||||
tmp->right = copyTrees(&(nodeToCopy.RightChild()));
|
||||
tmp->right = copyTree(&(nodeToCopy.RightChild()));
|
||||
else
|
||||
tmp->right = nullptr;
|
||||
|
||||
|
14
librerie/exercise3/binarytree/lnk/binarytreelnk.hpp
Normal file → Executable file
14
librerie/exercise3/binarytree/lnk/binarytreelnk.hpp
Normal file → Executable file
@@ -31,13 +31,11 @@ protected:
|
||||
|
||||
using BinaryTree<Data>::Node::data;
|
||||
struct NodeLnk* left;
|
||||
struct* NodeLnk* right;
|
||||
struct NodeLnk* right;
|
||||
|
||||
public:
|
||||
NodeLnk& operator=(const NodeLnk&); // Copy assignment of abstract types should not be possible.
|
||||
|
||||
// Move assignment
|
||||
Node& operator=(Node&&) noexcept override; // Move assignment of abstract types should not be possible.
|
||||
Node& operator=(const NodeLnk&); // Copy assignment of abstract types should not be possible.
|
||||
Node& operator=(NodeLnk&&) noexcept override; // Move assignment of abstract types should not be possible.
|
||||
bool IsLeaf() const noexcept override; // (concrete function should not throw exceptions)
|
||||
bool HasLeftChild() const noexcept override; // (concrete function should not throw exceptions)
|
||||
bool HasRightChild() const noexcept override; // (concrete function should not throw exceptions)
|
||||
@@ -52,7 +50,7 @@ protected:
|
||||
public:
|
||||
|
||||
// Default constructor
|
||||
BinaryTreeLnk();
|
||||
BinaryTreeLnk() = default;
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
@@ -75,10 +73,10 @@ public:
|
||||
/* ************************************************************************ */
|
||||
|
||||
// Copy assignment
|
||||
BinaryTreeLnk<Data>& operator=(const BinaryTreeLnk<Data>&);
|
||||
BinaryTreeLnk& operator=(const BinaryTreeLnk<Data>&);
|
||||
|
||||
// Move assignment
|
||||
BinaryTreeLnk<Data> operator=(BinaryTreeLnk<Data>&&) noexcept;
|
||||
BinaryTreeLnk& operator=(BinaryTreeLnk<Data>&&) noexcept;
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
|
Reference in New Issue
Block a user