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(Terminated()) throw std::out_of_range("Iterator is terminated!");
|
||||||
|
|
||||||
if(curr->HasLeftChild()){
|
if(curr->HasLeftChild()){
|
||||||
curr = &(curr->LeftChild());
|
|
||||||
|
|
||||||
if( curr->HasRightChild() )
|
if( curr->HasRightChild() ){
|
||||||
stack.Push(&curr->RightChild());
|
stack.Push(&(curr->RightChild()));
|
||||||
|
}
|
||||||
|
|
||||||
|
curr = &(curr->LeftChild());
|
||||||
|
|
||||||
}else if(curr->HasRightChild()){
|
}else if(curr->HasRightChild()){
|
||||||
curr = &curr->RightChild();
|
curr = &curr->RightChild();
|
||||||
}
|
}
|
||||||
else{
|
else{ // is leaf
|
||||||
try{
|
if(stack.Empty()){
|
||||||
curr = stack.TopNPop();
|
|
||||||
}catch(std:: length_error exc){
|
|
||||||
curr = nullptr;
|
curr = nullptr;
|
||||||
|
}else{
|
||||||
|
curr = stack.TopNPop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,12 +147,15 @@ bool BinaryTreeLnk<Data>::operator!=(const BinaryTreeLnk<Data>& tree) const noex
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::Root() const{
|
struct BinaryTree<Data>::Node& BinaryTreeLnk<Data>::Root() const{
|
||||||
|
if(size==0) throw std::length_error("Empty tree!");
|
||||||
return *root;
|
return *root;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void BinaryTreeLnk<Data>::Clear(){
|
void BinaryTreeLnk<Data>::Clear(){
|
||||||
DeleteTree(root);
|
DeleteTree(root);
|
||||||
|
root = nullptr;
|
||||||
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue