diff --git a/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp b/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp index 9a393f9..a14fe11 100755 --- a/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp +++ b/librerie/exercise3/binarytree/lnk/binarytreelnk.cpp @@ -35,12 +35,12 @@ bool BinaryTreeLnk::NodeLnk::HasRightChild() const noexcept{ } template -struct BinaryTree::Node& BinaryTreeLnk::NodeLnk::LeftChild() const{ +struct BinaryTreeLnk::NodeLnk& BinaryTreeLnk::NodeLnk::LeftChild() const{ return *left; } template -struct BinaryTree::Node& BinaryTreeLnk::NodeLnk::RightChild() const{ +struct BinaryTreeLnk::NodeLnk& BinaryTreeLnk::NodeLnk::RightChild() const{ return *right; } diff --git a/librerie/exercise3/binarytree/lnk/binarytreelnk.hpp b/librerie/exercise3/binarytree/lnk/binarytreelnk.hpp index b299fb8..85c852e 100755 --- a/librerie/exercise3/binarytree/lnk/binarytreelnk.hpp +++ b/librerie/exercise3/binarytree/lnk/binarytreelnk.hpp @@ -25,8 +25,8 @@ protected: bool HasLeftChild() const noexcept override; // (concrete function should not throw exceptions) bool HasRightChild() const noexcept override; // (concrete function should not throw exceptions) - struct BinaryTree::Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent) - struct BinaryTree::Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent) + struct NodeLnk& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent) + struct NodeLnk& RightChild() const override; // (concrete function must throw std::out_of_range when not existent) friend class BinaryTreeLnk; diff --git a/librerie/exercise3/binarytree/vec/binarytreevec.cpp b/librerie/exercise3/binarytree/vec/binarytreevec.cpp index ae60260..f954771 100755 --- a/librerie/exercise3/binarytree/vec/binarytreevec.cpp +++ b/librerie/exercise3/binarytree/vec/binarytreevec.cpp @@ -50,7 +50,7 @@ bool BinaryTreeVec::NodeVec::HasRightChild() const noexcept{ } template -struct BinaryTree::Node& BinaryTreeVec::NodeVec::LeftChild() const{ +struct BinaryTreeVec::NodeVec& BinaryTreeVec::NodeVec::LeftChild() const{ if(index*2+1 < ReferenceToTree->size) return *((ReferenceToTree->tree)[index*2+1]); else @@ -58,7 +58,7 @@ struct BinaryTree::Node& BinaryTreeVec::NodeVec::LeftChild() const{ } template -struct BinaryTree::Node& BinaryTreeVec::NodeVec::RightChild() const{ +struct BinaryTreeVec::NodeVec& BinaryTreeVec::NodeVec::RightChild() const{ if(index*2+2 < ReferenceToTree->size) return *((ReferenceToTree->tree)[index*2+2]); else diff --git a/librerie/exercise3/binarytree/vec/binarytreevec.hpp b/librerie/exercise3/binarytree/vec/binarytreevec.hpp index 9a334b2..e7e9abc 100755 --- a/librerie/exercise3/binarytree/vec/binarytreevec.hpp +++ b/librerie/exercise3/binarytree/vec/binarytreevec.hpp @@ -26,8 +26,8 @@ protected: 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) - struct BinaryTree::Node& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent) - struct BinaryTree::Node& RightChild() const override; // (concrete function must throw std::out_of_range when not existent) + struct NodeVec& LeftChild() const override; // (concrete function must throw std::out_of_range when not existent) + struct NodeVec& RightChild() const override; // (concrete function must throw std::out_of_range when not existent) friend class BinaryTreeVec; }; diff --git a/librerie/exercise3/zmytest/test.cpp b/librerie/exercise3/zmytest/test.cpp index affaf0e..d987b97 100755 --- a/librerie/exercise3/zmytest/test.cpp +++ b/librerie/exercise3/zmytest/test.cpp @@ -15,8 +15,10 @@ void menu(){ Implementation chosenImplementation; do{ - std::cout<<"1. Use your tests (to be used by the professor)"< "; std::cin>>std::ws; std::cin>>choice; }while(choice!=1 && choice!=2); @@ -36,9 +38,10 @@ DataType ChooseDataType(){ unsigned short int choice; do{ std::cout<<"\nChoose a data type:"< "; std::cin>>std::ws; std::cin>>choice; }while(!(choice>0 && choice<4)); @@ -53,8 +56,9 @@ Implementation ChooseImplementation(){ unsigned short int choice; do{ std::cout<<"\nChoose an implementation for the binary tree:"< "; std::cin>>std::ws; std::cin>>choice; }while(!(choice>0 && choice<3)); @@ -107,12 +111,14 @@ void IntegerFunctions(T& bt){ do{ std::cout< "; std::cin>>std::ws; std::cin>>choice; std::cout< @@ -142,12 +151,14 @@ void FloatFunctions(T& bt){ do{ std::cout< "; std::cin>>std::ws; std::cin>>choice; std::cout< @@ -177,12 +191,14 @@ void StringFunctions(T& bt){ do{ std::cout< "; std::cin>>std::ws; std::cin>>choice; std::cout< class Tree, typename DTType> +void Iterators(Tree& tree){ + uint choice; + cout< "; + cin>>ws; + cin>>choice; + switch(choice){ + case 1: + { + BTPreOrderIterator preitr(tree); + NavigateWithIterator(preitr); + } + break; + case 2: + { + BTPostOrderIterator postitr(tree); + NavigateWithIterator(postitr); + } + break; + case 3: + { + BTInOrderIterator initr(tree); + NavigateWithIterator(initr); + } + break; + case 4: + { + BTBreadthIterator breadthitr(tree); + NavigateWithIterator(breadthitr); + } + break; + } +} + +template