mirror of
https://github.com/xfarrow/lasd.git
synced 2025-06-05 21:49:14 +02:00
Library 3
fixed compile-time errors
This commit is contained in:
@@ -3,7 +3,7 @@ namespace lasd {
|
||||
|
||||
/* ************************************************************************** */
|
||||
template <typename Data>
|
||||
struct BinaryTreeLnk<Data>::NodeLnk& BinaryTreeLnk<Data>::NodeLnk::operator=(const NodeLnk& node){
|
||||
struct BinaryTreeLnk<Data>::NodeLnk& BinaryTreeLnk<Data>::NodeLnk::operator=(const BinaryTreeLnk<Data>::NodeLnk& node){
|
||||
data = node.data;
|
||||
left = node.left;
|
||||
right = node.right;
|
||||
@@ -34,12 +34,12 @@ bool BinaryTreeLnk<Data>::NodeLnk::HasRightChild() const noexcept{
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
Node& BinaryTreeLnk<Data>::NodeLnk::LeftChild() const{
|
||||
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::NodeLnk::LeftChild() const{
|
||||
return *left;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
Node& BinaryTreeLnk<Data>::NodeLnk::RightChild() const{
|
||||
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::NodeLnk::RightChild() const{
|
||||
return *right;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,8 @@ BinaryTreeLnk<Data>::BinaryTreeLnk(const LinearContainer<Data>& lc){
|
||||
size = lc.Size();
|
||||
}
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CreateTreeFromLinearContainerInBreadth(const LinearContainer<Data>& lc, ulong position){
|
||||
template <typename Data>
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* BinaryTreeLnk<Data>::CreateTreeFromLinearContainerInBreadth(const LinearContainer<Data>& lc, ulong position){
|
||||
if(position >= lc.Size()) return nullptr;
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* tmp = CreateNode(lc[position]);
|
||||
@@ -64,7 +65,7 @@ struct BinaryTreeLnk<Data>::NodeLnk* CreateTreeFromLinearContainerInBreadth(cons
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CreateNode(const Data& data){
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* BinaryTreeLnk<Data>::CreateNode(const Data& data){
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* newNode = new struct BinaryTreeLnk<Data>::NodeLnk();
|
||||
newNode->data = data;
|
||||
newNode->left = nullptr;
|
||||
@@ -79,18 +80,19 @@ BinaryTreeLnk<Data>::BinaryTreeLnk(const BinaryTreeLnk<Data>& tree){
|
||||
root = CopyTree(&tree.Root());
|
||||
}
|
||||
|
||||
BinaryTreeLnk<Data>::NodeLnk* BinaryTreeLnk<Data>::CopyTree(struct BinaryTreeLnk<Data>::NodeLnk* nodeToCopy){
|
||||
template <typename Data>
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* BinaryTreeLnk<Data>::CopyTree(struct BinaryTreeLnk<Data>::Node* nodeToCopy){
|
||||
if(nodeToCopy==nullptr) return nullptr;
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* tmp = CreateNode(nodeToCopy.Element());
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* tmp = CreateNode(nodeToCopy->Element());
|
||||
|
||||
if(nodeToCopy.HasLeftChild())
|
||||
tmp->left = copyTree(&(nodeToCopy.LeftChild()));
|
||||
if(nodeToCopy->HasLeftChild())
|
||||
tmp->left = CopyTree(&(nodeToCopy->LeftChild()));
|
||||
else
|
||||
tmp->left = nullptr;
|
||||
|
||||
if(nodeToCopy.HasRightChild())
|
||||
tmp->right = copyTree(&(nodeToCopy.RightChild()));
|
||||
if(nodeToCopy->HasRightChild())
|
||||
tmp->right = CopyTree(&(nodeToCopy->RightChild()));
|
||||
else
|
||||
tmp->right = nullptr;
|
||||
|
||||
@@ -144,12 +146,12 @@ bool BinaryTreeLnk<Data>::operator!=(const BinaryTreeLnk<Data>& tree) const noex
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
struct NodeLnk& Root() override{
|
||||
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::Root() const{
|
||||
return *root;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
void Clear() override{
|
||||
void BinaryTreeLnk<Data>::Clear(){
|
||||
DeleteTree(root);
|
||||
}
|
||||
|
||||
|
@@ -13,16 +13,14 @@ namespace lasd {
|
||||
/* ************************************************************************** */
|
||||
|
||||
template <typename Data>
|
||||
class BinaryTreeLnk : virtual protected BinaryTree<Data>{ // Must extend BinaryTree<Data>
|
||||
class BinaryTreeLnk : virtual public BinaryTree<Data>{ // Must extend BinaryTree<Data>
|
||||
|
||||
private:
|
||||
|
||||
protected:
|
||||
|
||||
using BinaryTree<Data>::size;
|
||||
struct NodeLnk* root = nullptr;
|
||||
|
||||
// Node
|
||||
struct NodeLnk : virtual protected BinaryTree<Data>::Node { // Must extend Node
|
||||
|
||||
private:
|
||||
@@ -34,19 +32,22 @@ protected:
|
||||
struct NodeLnk* right;
|
||||
|
||||
public:
|
||||
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.
|
||||
struct NodeLnk& operator=(const NodeLnk&); // Copy assignment of abstract types should not be possible.
|
||||
struct NodeLnk& operator=(NodeLnk&&) noexcept; // 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)
|
||||
|
||||
Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent)
|
||||
Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent)
|
||||
struct BinaryTree<Data>::Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent)
|
||||
struct BinaryTree<Data>::Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent)
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CreateNode(const Data& data);
|
||||
friend class BinaryTreeLnk<Data>;
|
||||
|
||||
};
|
||||
|
||||
protected:
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* root = nullptr;
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CreateNode(const Data& data);
|
||||
public:
|
||||
|
||||
// Default constructor
|
||||
@@ -88,7 +89,7 @@ public:
|
||||
|
||||
// Specific member functions (inherited from BinaryTree)
|
||||
|
||||
struct NodeLnk& Root() override; // Override BinaryTree member (throw std::length_error when empty)
|
||||
struct BinaryTree<Data>::Node& Root() const override; // Override BinaryTree member (throw std::length_error when empty)
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
@@ -97,8 +98,8 @@ public:
|
||||
void Clear() override; // Override Container member
|
||||
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CreateTreeFromLinearContainerInBreadth(const LinearContainer<Data>&,ulong);
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CopyTree(struct BinaryTreeLnk<Data>::NodeLnk*);
|
||||
void DeleteTree(BinaryTreeLnk<Data>::NodeLnk* node)
|
||||
struct BinaryTreeLnk<Data>::NodeLnk* CopyTree(struct BinaryTreeLnk<Data>::Node*);
|
||||
void DeleteTree(BinaryTreeLnk<Data>::NodeLnk* node);
|
||||
};
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
Reference in New Issue
Block a user