Library 3

bugfix
This commit is contained in:
Alessandro Ferro 2021-05-05 10:03:25 +02:00
parent 858e7debee
commit 4add56d732
2 changed files with 12 additions and 7 deletions

View File

@ -292,19 +292,21 @@ void BTPreOrderIterator<Data>::operator++(){
if(Terminated()) throw std::out_of_range("Iterator is terminated!");
if(curr->HasLeftChild()){
curr = &(curr->LeftChild());
if( curr->HasRightChild() )
stack.Push(&curr->RightChild());
if( curr->HasRightChild() ){
stack.Push(&(curr->RightChild()));
}
curr = &(curr->LeftChild());
}else if(curr->HasRightChild()){
curr = &curr->RightChild();
}
else{
try{
curr = stack.TopNPop();
}catch(std:: length_error exc){
else{ // is leaf
if(stack.Empty()){
curr = nullptr;
}else{
curr = stack.TopNPop();
}
}
}

View File

@ -147,12 +147,15 @@ bool BinaryTreeLnk<Data>::operator!=(const BinaryTreeLnk<Data>& tree) const noex
template <typename Data>
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::Root() const{
if(size==0) throw std::length_error("Empty tree!");
return *root;
}
template <typename Data>
void BinaryTreeLnk<Data>::Clear(){
DeleteTree(root);
root = nullptr;
size = 0;
}
}