Some encode/decode practice.
This commit is contained in:
parent
8a41337e2d
commit
ff962a6b16
29 changed files with 727 additions and 305 deletions
|
@ -6,37 +6,47 @@ template<typename T>
|
|||
class Node
|
||||
{
|
||||
public:
|
||||
Node(T data)
|
||||
: mData(data)
|
||||
{}
|
||||
Node(T data)
|
||||
: mData(data)
|
||||
{}
|
||||
|
||||
void addChild(std::unique_ptr<Node> child)
|
||||
{
|
||||
if(!mLeftChild)
|
||||
{
|
||||
mLeftChild = std::move(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
mRightChild = std::move(child);
|
||||
}
|
||||
}
|
||||
void addChild(std::unique_ptr<Node> child)
|
||||
{
|
||||
if(!mLeftChild)
|
||||
{
|
||||
mLeftChild = std::move(child);
|
||||
}
|
||||
else
|
||||
{
|
||||
mRightChild = std::move(child);
|
||||
}
|
||||
}
|
||||
|
||||
bool isLeaf() const
|
||||
{
|
||||
return !mLeftChild && !mRightChild;
|
||||
}
|
||||
bool isLeaf() const
|
||||
{
|
||||
return !mLeftChild && !mRightChild;
|
||||
}
|
||||
|
||||
T getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
T getData() const
|
||||
{
|
||||
return mData;
|
||||
}
|
||||
|
||||
Node* getLeftChild() const
|
||||
{
|
||||
return mLeftChild.get();
|
||||
}
|
||||
|
||||
Node* getRightChild() const
|
||||
{
|
||||
return mRightChild.get();
|
||||
}
|
||||
|
||||
private:
|
||||
T mData;
|
||||
unsigned char mTag{0};
|
||||
std::unique_ptr<Node> mLeftChild;
|
||||
std::unique_ptr<Node> mRightChild;
|
||||
T mData;
|
||||
unsigned char mTag{0};
|
||||
std::unique_ptr<Node> mLeftChild;
|
||||
std::unique_ptr<Node> mRightChild;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
@ -46,21 +56,21 @@ template<typename T>
|
|||
class Tree
|
||||
{
|
||||
public:
|
||||
Tree()
|
||||
{
|
||||
Tree()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void addRootNode(NodePtr<T> root)
|
||||
{
|
||||
mRootNode = std::move(root);
|
||||
}
|
||||
void addRootNode(NodePtr<T> root)
|
||||
{
|
||||
mRootNode = std::move(root);
|
||||
}
|
||||
|
||||
Node<T>* getRootNode() const
|
||||
{
|
||||
return mRootNode.get();
|
||||
}
|
||||
Node<T>* getRootNode() const
|
||||
{
|
||||
return mRootNode.get();
|
||||
}
|
||||
|
||||
private:
|
||||
NodePtr<T> mRootNode;
|
||||
NodePtr<T> mRootNode;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue