mirror of
https://github.com/xfarrow/lasd.git
synced 2025-06-05 21:49:14 +02:00
Library 3
bug fix: when size==0 and a BinaryTree[Lnk/Vec] is casted to BinaryTree, and operator== is called, it crashed
This commit is contained in:
@ -61,9 +61,13 @@ const Data& BinaryTree<Data>::Node::Element() const{
|
|||||||
/* ----- end of struct Node ----- */
|
/* ----- end of struct Node ----- */
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
bool BinaryTree<Data>::operator==(const BinaryTree& toCompare) const noexcept{
|
bool BinaryTree<Data>::operator==(const BinaryTree& tree) const noexcept{
|
||||||
if(size!=toCompare.size) return false;
|
if(size == tree.size){
|
||||||
return(Root() == toCompare.Root());
|
if(size == 0) return true;
|
||||||
|
else return (Root() == tree.Root());
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
|
@ -140,14 +140,15 @@ BinaryTreeLnk<Data>& BinaryTreeLnk<Data>::operator=(BinaryTreeLnk<Data>&& tree)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** operator== and operator!= can be removed from BinaryTreeLnk since they are
|
||||||
|
** inherited from BinaryTree. They're here just for clarity and because they're
|
||||||
|
** in the template.
|
||||||
|
** Maybe you can make them more optimized here.
|
||||||
|
*/
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
bool BinaryTreeLnk<Data>::operator==(const BinaryTreeLnk<Data>& tree) const noexcept{
|
bool BinaryTreeLnk<Data>::operator==(const BinaryTreeLnk<Data>& tree) const noexcept{
|
||||||
if(size == tree.size){
|
return (BinaryTree<Data>::operator==(tree));
|
||||||
if(size == 0) return true;
|
|
||||||
else return (Root() == tree.Root());
|
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
|
Reference in New Issue
Block a user