From 084a2df94e8a79995bafede7fce3882553700b5b Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Wed, 9 Jun 2021 12:03:18 +0200 Subject: [PATCH] Library 4 --- librerie/exercise4/binarytree/binarytree.cpp | 8 ++++---- librerie/exercise4/binarytree/lnk/binarytreelnk.cpp | 1 - librerie/exercise4/binarytree/vec/binarytreevec.cpp | 4 +++- librerie/exercise4/list/list.cpp | 2 +- librerie/exercise4/queue/vec/queuevec.cpp | 4 ++-- librerie/exercise4/stack/lst/stacklst.cpp | 2 +- librerie/exercise4/stack/vec/stackvec.cpp | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/librerie/exercise4/binarytree/binarytree.cpp b/librerie/exercise4/binarytree/binarytree.cpp index 028f727..862cde2 100755 --- a/librerie/exercise4/binarytree/binarytree.cpp +++ b/librerie/exercise4/binarytree/binarytree.cpp @@ -465,8 +465,8 @@ BTInOrderIterator::BTInOrderIterator(const BTInOrderIterator& itr){ template BTInOrderIterator::BTInOrderIterator(BTInOrderIterator&& toMove) noexcept{ - std::move(curr, toMove.curr); - std::move(stack, toMove.stack); + std::swap(curr, toMove.curr); + std::swap(stack, toMove.stack); } template @@ -484,8 +484,8 @@ BTInOrderIterator& BTInOrderIterator::operator=(const BTInOrderItera template BTInOrderIterator& BTInOrderIterator::operator=(BTInOrderIterator&& toMove) noexcept{ - std::move(curr, toMove.curr); - std::move(stack, toMove.stack); + std::swap(curr, toMove.curr); + std::swap(stack, toMove.stack); return *this; } diff --git a/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp b/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp index eca6ed9..3167335 100755 --- a/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp +++ b/librerie/exercise4/binarytree/lnk/binarytreelnk.cpp @@ -134,7 +134,6 @@ BinaryTreeLnk& BinaryTreeLnk::operator=(const BinaryTreeLnk& t template BinaryTreeLnk& BinaryTreeLnk::operator=(BinaryTreeLnk&& tree) noexcept{ - Clear(); std::swap(size, tree.size); std::swap(root, tree.root); return *this; diff --git a/librerie/exercise4/binarytree/vec/binarytreevec.cpp b/librerie/exercise4/binarytree/vec/binarytreevec.cpp index f954771..2bc3694 100755 --- a/librerie/exercise4/binarytree/vec/binarytreevec.cpp +++ b/librerie/exercise4/binarytree/vec/binarytreevec.cpp @@ -117,12 +117,14 @@ BinaryTreeVec& BinaryTreeVec::operator=(const BinaryTreeVec& b template BinaryTreeVec& BinaryTreeVec::operator=(BinaryTreeVec&& bt) noexcept{ - Clear(); std::swap(size, bt.size); std::swap(tree, bt.tree); for(ulong i=0 ; iReferenceToTree = this; } + for(ulong j=0 ; jReferenceToTree = &bt; + } return *this; } diff --git a/librerie/exercise4/list/list.cpp b/librerie/exercise4/list/list.cpp index 3396301..05c06d1 100644 --- a/librerie/exercise4/list/list.cpp +++ b/librerie/exercise4/list/list.cpp @@ -167,7 +167,7 @@ void List::InsertAtBack(const Data& data){ template void List::InsertAtBack(Data&& data){ if(size == 0){ - InsertAtFront(data); + InsertAtFront(std::move(data)); } else{ struct Node* last = new Node(std::move(data)); diff --git a/librerie/exercise4/queue/vec/queuevec.cpp b/librerie/exercise4/queue/vec/queuevec.cpp index 42f6857..a76066f 100755 --- a/librerie/exercise4/queue/vec/queuevec.cpp +++ b/librerie/exercise4/queue/vec/queuevec.cpp @@ -37,7 +37,7 @@ QueueVec::QueueVec(const QueueVec& toCopy){ template QueueVec::QueueVec(QueueVec&& toMove) noexcept{ - Clear(); + Clear(); // the moved Queue will be in a consistent state std::swap(Elements, toMove.Elements); std::swap(rear, toMove.rear); std::swap(front, toMove.front); @@ -140,7 +140,7 @@ bool QueueVec::Empty() const noexcept{ template ulong QueueVec::Size() const noexcept{ - //if(size == 0) return 0; // this won't ever get executed, it's here just in case + //if(size == 0) return 0; // this won't ever get executed, it's here just in case return ((rear + size) - front) % size; } diff --git a/librerie/exercise4/stack/lst/stacklst.cpp b/librerie/exercise4/stack/lst/stacklst.cpp index f1f24d8..a9b6cdc 100755 --- a/librerie/exercise4/stack/lst/stacklst.cpp +++ b/librerie/exercise4/stack/lst/stacklst.cpp @@ -52,7 +52,7 @@ void StackLst::Push(const Data& element){ template void StackLst::Push(Data&& element) noexcept{ - List::InsertAtFront(element); + List::InsertAtFront(std::move(element)); } template diff --git a/librerie/exercise4/stack/vec/stackvec.cpp b/librerie/exercise4/stack/vec/stackvec.cpp index eabb6ad..ca711d3 100755 --- a/librerie/exercise4/stack/vec/stackvec.cpp +++ b/librerie/exercise4/stack/vec/stackvec.cpp @@ -44,7 +44,7 @@ StackVec& StackVec::operator=(const StackVec& copyFrom){ template StackVec& StackVec::operator=(StackVec&& moveFrom) noexcept{ Vector::operator=(std::move(moveFrom)); - stackSize = moveFrom.Size(); + std::swap(stackSize, moveFrom.stackSize); return *this; }