mirror of https://github.com/xfarrow/lasd.git
Library 3
This commit is contained in:
parent
b6f6baeede
commit
65942205cd
|
@ -1,5 +1,11 @@
|
|||
|
||||
// #include "..."
|
||||
#include "../queue/queue.hpp"
|
||||
#include "../queue/vec/queuevec.hpp"
|
||||
#include "../queue/lst/queuelst.hpp"
|
||||
|
||||
#include "../stack/stack.hpp"
|
||||
#include "../stack/lst/stacklst.hpp"
|
||||
#include "../stack/vec/stackvec.hpp"
|
||||
|
||||
namespace lasd {
|
||||
|
||||
|
@ -364,23 +370,18 @@ bool BTPostOrderIterator<Data>::Terminated() noexcept{
|
|||
template <typename Data>
|
||||
void BTPostOrderIterator<Data>::operator++(){
|
||||
if(Terminated()) throw std::out_of_range("Iterator is terminated!");
|
||||
|
||||
if(curr == &stack.Top().LeftChild()){
|
||||
if(stack.Top().HasRightChild()){
|
||||
curr = DeepestLeftLeaf(&stack.Top().RightChild());
|
||||
}else{
|
||||
try{
|
||||
try{
|
||||
if(curr == &stack.Top().LeftChild()){
|
||||
if(stack.Top().HasRightChild()){
|
||||
curr = DeepestLeftLeaf(&stack.Top().RightChild());
|
||||
}else{
|
||||
curr = &stack.TopNPop();
|
||||
}catch(std::length_error exc){
|
||||
curr = nullptr;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
try{
|
||||
}else{
|
||||
curr = &stack.TopNPop();
|
||||
}catch(std::length_error exc){
|
||||
curr = nullptr;
|
||||
}
|
||||
}catch(std::length_error exc){
|
||||
curr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -466,18 +467,78 @@ void BTInOrdertOrderIterator<Data>::operator++(){
|
|||
}
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BTBreadthIterator<Data>::BTBreadthIterator(const BinaryTree<Data>& tree){
|
||||
curr = &(tree.Root());
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BTBreadthIterator<Data>::BTBreadthIterator(const BTBreadthIterator& itr){
|
||||
curr = itr.curr;
|
||||
queue = itr.queue;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BTBreadthIterator<Data>::BTBreadthIterator(BTBreadthIterator&& itr) noexcept{
|
||||
std::swap(curr, itr.curr);
|
||||
std::swap(queue, itr.queue);
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BTBreadthIterator<Data>::~BTBreadthIterator(){
|
||||
curr = nullptr;
|
||||
queue.Clear();
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BTBreadthIterator& BTBreadthIterator<Data>::operator=(const BTBreadthIterator& itr){
|
||||
curr = itr.curr;
|
||||
queue = itr.queue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
BTBreadthIterator& BTBreadthIterator<Data>::operator=(BTBreadthIterator&& itr) noexcept{
|
||||
std::swap(curr, itr.curr);
|
||||
std::swap(queue, itr.queue);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
bool BTBreadthIterator<Data>::operator==(const BTBreadthIterator& itr) const noexcept{
|
||||
return ( curr==itr.curr && queue==itr.queue );
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
bool BTBreadthIterator<Data>::operator!=(const BTBreadthIterator& itr) const noexcept{
|
||||
return !(*this == itr);
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
struct BinaryTree<Data>::Node BTBreadthIterator<Data>::operator*() const{
|
||||
return *curr;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
bool BTBreadthIterator<Data>::Terminated() noexcept{
|
||||
return curr == nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename Data>
|
||||
void BTBreadthIterator<Data>::operator++(){
|
||||
if(Terminated()) throw std::out_of_range("Iterator is terminated!");
|
||||
if(curr->HasLeftChild()){
|
||||
queue.Enqueue(&(curr->LeftChild()));
|
||||
}
|
||||
if(curr->HasRightChild()){
|
||||
queue.Enqueue(&(curr->RightChild()));
|
||||
}
|
||||
if(!queue.Empty()){
|
||||
curr = queue.HeadNDequeue();
|
||||
}else{
|
||||
curr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
|
@ -13,43 +13,48 @@ namespace lasd {
|
|||
/* ************************************************************************** */
|
||||
|
||||
template <typename Data>
|
||||
class BinaryTreeLnk { // Must extend BinaryTree<Data>
|
||||
class BinaryTreeLnk : virtual protected BinaryTree<Data>{ // Must extend BinaryTree<Data>
|
||||
|
||||
private:
|
||||
|
||||
// ...
|
||||
|
||||
protected:
|
||||
|
||||
// using BinaryTree<Data>::???;
|
||||
using BinaryTree<Data>::size;
|
||||
|
||||
// ...
|
||||
|
||||
struct NodeLnk { // Must extend Node
|
||||
struct NodeLnk : virtual protected BinaryTree<Data>::Node { // Must extend Node
|
||||
|
||||
private:
|
||||
|
||||
// ...
|
||||
|
||||
protected:
|
||||
|
||||
// ...
|
||||
using BinaryTree<Data>::Node::data;
|
||||
struct NodeLnk* left;
|
||||
struct* NodeLnk* right;
|
||||
|
||||
public:
|
||||
|
||||
// ...
|
||||
NodeLnk& operator=(const Node&); // Copy assignment of abstract types should not be possible.
|
||||
|
||||
// Move assignment
|
||||
NodeLnk& operator=(Node&&) 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)
|
||||
|
||||
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)
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// Default constructor
|
||||
// BinaryTreeLnk() specifiers;
|
||||
BinaryTreeLnk();
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
// Specific constructors
|
||||
// BinaryTreeLnk(argument) specifiers; // A binary tree obtained from a LinearContainer
|
||||
BinaryTreeLnk(argument) specifiers; // A binary tree obtained from a LinearContainer
|
||||
|
||||
/* ************************************************************************ */
|
||||
|
||||
|
|
Loading…
Reference in New Issue