mirror of
https://github.com/xfarrow/lasd.git
synced 2025-06-05 21:49:14 +02:00
Library 2
This commit is contained in:
@ -6,6 +6,7 @@ namespace lasd {
|
||||
template <typename Data>
|
||||
StackVec<Data>::StackVec(){
|
||||
size = 4; // default vector is instantiated with 4 cells
|
||||
stackSize = 0;
|
||||
Elements = new Data[size];
|
||||
}
|
||||
|
||||
@ -21,12 +22,12 @@ StackVec<Data>::StackVec(const LinearContainer<Data>& linear){ // si può richia
|
||||
|
||||
template <typename Data>
|
||||
StackVec<Data>::StackVec(const StackVec& stckvec){// si può richiamare il costruttore della classe Vector
|
||||
Elements = new Data[stckvec.Size()]; // espandere di un po' forse
|
||||
for(ulong i=0 ; i<stckvec.Size() ; ++i){
|
||||
Elements = new Data[stckvec.size]; // espandere di un po' forse
|
||||
for(ulong i=0 ; i<stckvec.size ; ++i){
|
||||
Elements[i] = stckvec[i];
|
||||
}
|
||||
size = stckvec.Size();
|
||||
stackSize = stckvec.stackSize;
|
||||
size = stckvec.size;
|
||||
stackSize = stckvec.Size();
|
||||
}
|
||||
/*
|
||||
StackVec(const StackVec& stckvec) : Vector<Data>(copyFrom)
|
||||
@ -39,32 +40,42 @@ StackVec<Data>::StackVec(StackVec&& toMove) noexcept{
|
||||
std::swap(stackSize, toMove.stackSize);
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
StackVec<Data>::~StackVec(){
|
||||
// Vector destructor will be called automatically
|
||||
// (TEST IT)
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
StackVec& StackVec<Data>::operator=(const StackVec& copyFrom){
|
||||
StackVec<Data>& StackVec<Data>::operator=(const StackVec<Data>& copyFrom){
|
||||
Vector<Data>::operator=(copyFrom); // espandere di un po' forse
|
||||
stackSize = copyFrom.Size();
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
StackVec& StackVec<Data>::operator=(StackVec&& moveFrom) noexcept{
|
||||
StackVec<Data>& StackVec<Data>::operator=(StackVec<Data>&& moveFrom) noexcept{
|
||||
Vector<Data>::operator=(std::move(moveFrom)); // espandere di un po' forse
|
||||
stackSize = copyFrom.Size();
|
||||
stackSize = moveFrom.Size();
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
bool StackVec<Data>::operator==(const StackVec& toCompare) const noexcept{
|
||||
Vector<Data>::operator==(toCompare);
|
||||
bool StackVec<Data>::operator==(const StackVec<Data>& toCompare) const noexcept{
|
||||
if(stackSize == toCompare.Size()){
|
||||
for(ulong i=0 ; i<stackSize ; ++i){
|
||||
if(Elements[i] != toCompare[i]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
bool StackVec<Data>::operator!=(const StackVec& toCompare) const noexcept{
|
||||
Vector<Data>::operator!=(toCompare);
|
||||
bool StackVec<Data>::operator!=(const StackVec<Data>& toCompare) const noexcept{
|
||||
return !(*this == toCompare);
|
||||
}
|
||||
|
||||
// Specific member functions (inherited from Stack)
|
||||
@ -83,20 +94,21 @@ void StackVec<Data>::Push(Data&& data){
|
||||
Expand();
|
||||
}
|
||||
std::swap(Elements[stackSize], data);
|
||||
++stackSize;
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
Data& StackVec<Data>::Top() const{
|
||||
if(stackSize == 0){
|
||||
throw std::length_error("Empty Stack!");
|
||||
throw std::length_error("Empty Stack! (TOP)");
|
||||
}
|
||||
return Elements[stackSize-1]
|
||||
return Elements[stackSize-1];
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
void StackVec<Data>::Pop(){
|
||||
if(stackSize<=0){
|
||||
throw std::length_error("Empty Stack!");
|
||||
if(stackSize==0){
|
||||
throw std::length_error("Empty Stack! (POP)");
|
||||
}
|
||||
--stackSize;
|
||||
if(stackSize < (int)(size/4)){
|
||||
@ -131,6 +143,13 @@ void StackVec<Data>::Reduce(){
|
||||
Vector<Data>::Resize((ulong)size/2);
|
||||
}
|
||||
|
||||
template <typename Data>
|
||||
void StackVec<Data>::Clear(){
|
||||
delete [] Elements;
|
||||
size = 4;
|
||||
stackSize = 0;
|
||||
Elements = new Data[size];
|
||||
}
|
||||
/* ************************************************************************** */
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user