mirror of https://github.com/xfarrow/lasd.git
parent
858e7debee
commit
4add56d732
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue