diff --git a/librerie/exercise3/binarytree/binarytree.cpp b/librerie/exercise3/binarytree/binarytree.cpp index b616cb7..a7f62a5 100755 --- a/librerie/exercise3/binarytree/binarytree.cpp +++ b/librerie/exercise3/binarytree/binarytree.cpp @@ -245,7 +245,10 @@ void BinaryTree::FoldBreadth(const typename FoldableContainer::FoldF template BTPreOrderIterator::BTPreOrderIterator(const BinaryTree& tree){ - curr = &tree.Root(); + if(tree.Size() > 0) + curr = &tree.Root(); + else + curr = nullptr; } template @@ -345,7 +348,10 @@ struct BinaryTree::Node* BTPostOrderIterator::DeepestLeftLeaf(struct template BTPostOrderIterator::BTPostOrderIterator(const BinaryTree& tree){ - curr = DeepestLeftLeaf(&tree.Root()); + if(tree.Size() > 0) + curr = DeepestLeftLeaf(&tree.Root()); + else + curr = nullptr; } template @@ -441,7 +447,10 @@ struct BinaryTree::Node* BTInOrderIterator::MostLeftNode(struct Bina template BTInOrderIterator::BTInOrderIterator(const BinaryTree& tree){ - curr = MostLeftNode(tree.Root()); + if(tree.Size() > 0) + curr = MostLeftNode(tree.Root()); + else + curr = nullptr; } template @@ -518,7 +527,10 @@ void BTInOrderIterator::operator++(){ template BTBreadthIterator::BTBreadthIterator(const BinaryTree& tree){ - curr = &(tree.Root()); + if(tree.Size() > 0) + curr = &(tree.Root()); + else + curr = nullptr; } template diff --git a/librerie/exercise3/build.sh b/librerie/exercise3/build.sh index f4b1d27..bd9c16e 100755 --- a/librerie/exercise3/build.sh +++ b/librerie/exercise3/build.sh @@ -1,7 +1,7 @@ #! /bin/bash -g++ -g -o main \ +g++ -O3 -o main \ zlasdtest/exercise1/simpletest.cpp zlasdtest/exercise1/fulltest.cpp \ zlasdtest/exercise2/simpletest.cpp zlasdtest/exercise2/fulltest.cpp \ zlasdtest/exercise3/simpletest.cpp zlasdtest/exercise3/fulltest.cpp \ diff --git a/librerie/exercise3/zmytest/test.cpp b/librerie/exercise3/zmytest/test.cpp index d987b97..8cec8b8 100755 --- a/librerie/exercise3/zmytest/test.cpp +++ b/librerie/exercise3/zmytest/test.cpp @@ -116,8 +116,9 @@ void IntegerFunctions(T& bt){ std::cout<<" 3. Product of integers less than 'n' "< "; std::cin>>std::ws; std::cin>>choice; @@ -138,11 +139,17 @@ void IntegerFunctions(T& bt){ case 5: Iterators(bt); break; - case 6: + case 6: + if(bt.Size() > 0) + NodeOperations(bt.Root()); + else + cout<<"\nThe tree does not have any nodes..."; + break; + case 7: menu(); break; } - }while(choice!=6 && choice!=7); + }while(choice!=7 && choice!=8); } template @@ -156,8 +163,9 @@ void FloatFunctions(T& bt){ std::cout<<" 3. Sum of floats greater than 'n' "< "; std::cin>>std::ws; std::cin>>choice; @@ -178,11 +186,17 @@ void FloatFunctions(T& bt){ case 5: Iterators(bt); break; - case 6: + case 6: + if(bt.Size() > 0) + NodeOperations(bt.Root()); + else + cout<<"\nThe tree does not have any nodes..."; + break; + case 7: menu(); break; } - }while(choice!=6 && choice!=7); + }while(choice!=7 && choice!=8); } template @@ -196,8 +210,9 @@ void StringFunctions(T& bt){ std::cout<<" 3. Concatenate strings whose dimension is less or equal than 'n' "< "; std::cin>>std::ws; std::cin>>choice; @@ -219,10 +234,16 @@ void StringFunctions(T& bt){ Iterators(bt); break; case 6: + if(bt.Size() > 0) + NodeOperations(bt.Root()); + else + cout<<"\nThe tree does not have any nodes..."; + break; + case 7: menu(); break; } - }while(choice!=6 && choice!=7); + }while(choice!=7 && choice!=8); } /* ----- integer functions ----- */ @@ -388,29 +409,29 @@ void Iterators(Tree& tree){ break; } } - -template