From a6485b86afb1fcfb200df8df28d8b60f76c2bede Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Tue, 6 Jul 2021 00:00:36 +0200 Subject: [PATCH] Update --- librerie/exercise2/queue/vec/queuevec.cpp | 12 ++++++------ librerie/exercise2/stack/vec/stackvec.cpp | 10 +++++----- librerie/exercise3/queue/vec/queuevec.cpp | 12 ++++++------ librerie/exercise3/stack/vec/stackvec.cpp | 10 +++++----- librerie/exercise4/queue/vec/queuevec.cpp | 12 ++++++------ librerie/exercise4/stack/vec/stackvec.cpp | 10 +++++----- librerie/exercise5/queue/vec/queuevec.cpp | 12 ++++++------ librerie/exercise5/stack/vec/stackvec.cpp | 10 +++++----- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/librerie/exercise2/queue/vec/queuevec.cpp b/librerie/exercise2/queue/vec/queuevec.cpp index a76066f..5e081a2 100755 --- a/librerie/exercise2/queue/vec/queuevec.cpp +++ b/librerie/exercise2/queue/vec/queuevec.cpp @@ -1,9 +1,9 @@ - +#define MINSIZE 4 namespace lasd { template QueueVec::QueueVec(){ - size = 4; + size = MINSIZE; rear = 0; front = 0; Elements = new Data[size]; @@ -146,10 +146,10 @@ ulong QueueVec::Size() const noexcept{ template void QueueVec::Clear(){ - if(size!=4){ + if(size!=MINSIZE){ delete[] Elements; - Elements = new Data[4]; - size = 4; + Elements = new Data[MINSIZE]; + size = MINSIZE; } front = 0; rear = 0; @@ -173,7 +173,7 @@ void QueueVec::Expand(){ template void QueueVec::Reduce(){ - if(size<=4) return; // we are not going to have vectors with less than 4 Elements + if(size<(MINSIZE*2)) return; // we are not going to have vectors with less than 4 Elements ulong newsize = (ulong)size/2; Data* tmp = new Data[newsize]; ulong current_index = front , i=0; diff --git a/librerie/exercise2/stack/vec/stackvec.cpp b/librerie/exercise2/stack/vec/stackvec.cpp index ca711d3..356f759 100755 --- a/librerie/exercise2/stack/vec/stackvec.cpp +++ b/librerie/exercise2/stack/vec/stackvec.cpp @@ -1,11 +1,11 @@ - +#define MINSIZE 4 namespace lasd { /* ************************************************************************** */ // constructors template StackVec::StackVec(){ - size = 4; // default vector is instantiated with 4 cells + size = MINSIZE; // default vector is instantiated with 4 cells stackSize = 0; Elements = new Data[size]; } @@ -129,15 +129,15 @@ void StackVec::Expand(){ template void StackVec::Reduce(){ - if(size <= 4) return; // we're not going to have vectors with less than 4 cells + if(size < (MINSIZE*2)) return; // we're not going to have vectors with less than 4 cells Vector::Resize((ulong)size/2); } template void StackVec::Clear(){ delete [] Elements; - size = 4; + size = MINSIZE; stackSize = 0; - Elements = new Data[size]; + Elements = new Data[MINSIZE]; } } diff --git a/librerie/exercise3/queue/vec/queuevec.cpp b/librerie/exercise3/queue/vec/queuevec.cpp index a76066f..5e081a2 100755 --- a/librerie/exercise3/queue/vec/queuevec.cpp +++ b/librerie/exercise3/queue/vec/queuevec.cpp @@ -1,9 +1,9 @@ - +#define MINSIZE 4 namespace lasd { template QueueVec::QueueVec(){ - size = 4; + size = MINSIZE; rear = 0; front = 0; Elements = new Data[size]; @@ -146,10 +146,10 @@ ulong QueueVec::Size() const noexcept{ template void QueueVec::Clear(){ - if(size!=4){ + if(size!=MINSIZE){ delete[] Elements; - Elements = new Data[4]; - size = 4; + Elements = new Data[MINSIZE]; + size = MINSIZE; } front = 0; rear = 0; @@ -173,7 +173,7 @@ void QueueVec::Expand(){ template void QueueVec::Reduce(){ - if(size<=4) return; // we are not going to have vectors with less than 4 Elements + if(size<(MINSIZE*2)) return; // we are not going to have vectors with less than 4 Elements ulong newsize = (ulong)size/2; Data* tmp = new Data[newsize]; ulong current_index = front , i=0; diff --git a/librerie/exercise3/stack/vec/stackvec.cpp b/librerie/exercise3/stack/vec/stackvec.cpp index ca711d3..356f759 100755 --- a/librerie/exercise3/stack/vec/stackvec.cpp +++ b/librerie/exercise3/stack/vec/stackvec.cpp @@ -1,11 +1,11 @@ - +#define MINSIZE 4 namespace lasd { /* ************************************************************************** */ // constructors template StackVec::StackVec(){ - size = 4; // default vector is instantiated with 4 cells + size = MINSIZE; // default vector is instantiated with 4 cells stackSize = 0; Elements = new Data[size]; } @@ -129,15 +129,15 @@ void StackVec::Expand(){ template void StackVec::Reduce(){ - if(size <= 4) return; // we're not going to have vectors with less than 4 cells + if(size < (MINSIZE*2)) return; // we're not going to have vectors with less than 4 cells Vector::Resize((ulong)size/2); } template void StackVec::Clear(){ delete [] Elements; - size = 4; + size = MINSIZE; stackSize = 0; - Elements = new Data[size]; + Elements = new Data[MINSIZE]; } } diff --git a/librerie/exercise4/queue/vec/queuevec.cpp b/librerie/exercise4/queue/vec/queuevec.cpp index a76066f..5e081a2 100755 --- a/librerie/exercise4/queue/vec/queuevec.cpp +++ b/librerie/exercise4/queue/vec/queuevec.cpp @@ -1,9 +1,9 @@ - +#define MINSIZE 4 namespace lasd { template QueueVec::QueueVec(){ - size = 4; + size = MINSIZE; rear = 0; front = 0; Elements = new Data[size]; @@ -146,10 +146,10 @@ ulong QueueVec::Size() const noexcept{ template void QueueVec::Clear(){ - if(size!=4){ + if(size!=MINSIZE){ delete[] Elements; - Elements = new Data[4]; - size = 4; + Elements = new Data[MINSIZE]; + size = MINSIZE; } front = 0; rear = 0; @@ -173,7 +173,7 @@ void QueueVec::Expand(){ template void QueueVec::Reduce(){ - if(size<=4) return; // we are not going to have vectors with less than 4 Elements + if(size<(MINSIZE*2)) return; // we are not going to have vectors with less than 4 Elements ulong newsize = (ulong)size/2; Data* tmp = new Data[newsize]; ulong current_index = front , i=0; diff --git a/librerie/exercise4/stack/vec/stackvec.cpp b/librerie/exercise4/stack/vec/stackvec.cpp index ca711d3..356f759 100755 --- a/librerie/exercise4/stack/vec/stackvec.cpp +++ b/librerie/exercise4/stack/vec/stackvec.cpp @@ -1,11 +1,11 @@ - +#define MINSIZE 4 namespace lasd { /* ************************************************************************** */ // constructors template StackVec::StackVec(){ - size = 4; // default vector is instantiated with 4 cells + size = MINSIZE; // default vector is instantiated with 4 cells stackSize = 0; Elements = new Data[size]; } @@ -129,15 +129,15 @@ void StackVec::Expand(){ template void StackVec::Reduce(){ - if(size <= 4) return; // we're not going to have vectors with less than 4 cells + if(size < (MINSIZE*2)) return; // we're not going to have vectors with less than 4 cells Vector::Resize((ulong)size/2); } template void StackVec::Clear(){ delete [] Elements; - size = 4; + size = MINSIZE; stackSize = 0; - Elements = new Data[size]; + Elements = new Data[MINSIZE]; } } diff --git a/librerie/exercise5/queue/vec/queuevec.cpp b/librerie/exercise5/queue/vec/queuevec.cpp index a76066f..5e081a2 100755 --- a/librerie/exercise5/queue/vec/queuevec.cpp +++ b/librerie/exercise5/queue/vec/queuevec.cpp @@ -1,9 +1,9 @@ - +#define MINSIZE 4 namespace lasd { template QueueVec::QueueVec(){ - size = 4; + size = MINSIZE; rear = 0; front = 0; Elements = new Data[size]; @@ -146,10 +146,10 @@ ulong QueueVec::Size() const noexcept{ template void QueueVec::Clear(){ - if(size!=4){ + if(size!=MINSIZE){ delete[] Elements; - Elements = new Data[4]; - size = 4; + Elements = new Data[MINSIZE]; + size = MINSIZE; } front = 0; rear = 0; @@ -173,7 +173,7 @@ void QueueVec::Expand(){ template void QueueVec::Reduce(){ - if(size<=4) return; // we are not going to have vectors with less than 4 Elements + if(size<(MINSIZE*2)) return; // we are not going to have vectors with less than 4 Elements ulong newsize = (ulong)size/2; Data* tmp = new Data[newsize]; ulong current_index = front , i=0; diff --git a/librerie/exercise5/stack/vec/stackvec.cpp b/librerie/exercise5/stack/vec/stackvec.cpp index ca711d3..356f759 100755 --- a/librerie/exercise5/stack/vec/stackvec.cpp +++ b/librerie/exercise5/stack/vec/stackvec.cpp @@ -1,11 +1,11 @@ - +#define MINSIZE 4 namespace lasd { /* ************************************************************************** */ // constructors template StackVec::StackVec(){ - size = 4; // default vector is instantiated with 4 cells + size = MINSIZE; // default vector is instantiated with 4 cells stackSize = 0; Elements = new Data[size]; } @@ -129,15 +129,15 @@ void StackVec::Expand(){ template void StackVec::Reduce(){ - if(size <= 4) return; // we're not going to have vectors with less than 4 cells + if(size < (MINSIZE*2)) return; // we're not going to have vectors with less than 4 cells Vector::Resize((ulong)size/2); } template void StackVec::Clear(){ delete [] Elements; - size = 4; + size = MINSIZE; stackSize = 0; - Elements = new Data[size]; + Elements = new Data[MINSIZE]; } }