mirror of https://github.com/xfarrow/lasd.git
parent
aa9dcc16cf
commit
0a8d458eb1
Binary file not shown.
|
@ -15,42 +15,23 @@ StackVec<Data>::StackVec(const LinearContainer<Data>& linear)
|
||||||
: Vector<Data>(linear){
|
: Vector<Data>(linear){
|
||||||
stackSize = linear.Size(); // the array is full
|
stackSize = linear.Size(); // the array is full
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
template <typename Data>
|
|
||||||
StackVec<Data>::StackVec(const LinearContainer<Data>& linear){ // si può richiamare il costruttore della classe Vector
|
|
||||||
Elements = new Data[linear.Size()]; // espandere di un po' forse
|
|
||||||
for(ulong i=0 ; i<linear.Size() ; ++i){
|
|
||||||
Elements[i] = linear[i];
|
|
||||||
}
|
|
||||||
size = linear.Size();
|
|
||||||
stackSize = linear.Size();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
StackVec<Data>::StackVec(const StackVec& stckvec){// si può richiamare il costruttore della classe Vector
|
StackVec<Data>::StackVec(const StackVec& stckvec)
|
||||||
Elements = new Data[stckvec.size]; // espandere di un po' forse
|
: Vector<Data>(stckvec){
|
||||||
for(ulong i=0 ; i<stckvec.size ; ++i){
|
stackSize = stckvec.Size(); // the array is full
|
||||||
Elements[i] = stckvec[i];
|
|
||||||
}
|
}
|
||||||
size = stckvec.size;
|
|
||||||
stackSize = stckvec.Size();
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
StackVec(const StackVec& stckvec) : Vector<Data>(copyFrom)
|
|
||||||
*/
|
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
StackVec<Data>::StackVec(StackVec&& toMove) noexcept{
|
StackVec<Data>::StackVec(StackVec&& toMove) noexcept
|
||||||
std::swap(Elements, toMove.Elements);
|
: Vector<Data>(std::move(toMove)){
|
||||||
std::swap(size, toMove.size);
|
|
||||||
std::swap(stackSize, toMove.stackSize);
|
std::swap(stackSize, toMove.stackSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
StackVec<Data>::~StackVec(){
|
StackVec<Data>::~StackVec(){
|
||||||
// Vector destructor will be called automatically
|
// Vector destructor will be called automatically
|
||||||
// (TEST IT)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
|
@ -62,8 +43,9 @@ StackVec<Data>& StackVec<Data>::operator=(const StackVec<Data>& copyFrom){
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
StackVec<Data>& StackVec<Data>::operator=(StackVec<Data>&& moveFrom) noexcept{
|
StackVec<Data>& StackVec<Data>::operator=(StackVec<Data>&& moveFrom) noexcept{
|
||||||
Vector<Data>::operator=(std::move(moveFrom)); // espandere di un po' forse
|
Vector<Data>::operator=(std::move(moveFrom));
|
||||||
stackSize = moveFrom.Size();
|
stackSize = moveFrom.Size();
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
|
@ -107,7 +89,7 @@ void StackVec<Data>::Push(Data&& data){
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
Data& StackVec<Data>::Top() const{
|
Data& StackVec<Data>::Top() const{
|
||||||
if(stackSize == 0){
|
if(stackSize == 0){
|
||||||
throw std::length_error("Empty Stack! (TOP)");
|
throw std::length_error("Empty Stack!");
|
||||||
}
|
}
|
||||||
return Elements[stackSize-1];
|
return Elements[stackSize-1];
|
||||||
}
|
}
|
||||||
|
@ -115,7 +97,7 @@ Data& StackVec<Data>::Top() const{
|
||||||
template <typename Data>
|
template <typename Data>
|
||||||
void StackVec<Data>::Pop(){
|
void StackVec<Data>::Pop(){
|
||||||
if(stackSize==0){
|
if(stackSize==0){
|
||||||
throw std::length_error("Empty Stack! (POP)");
|
throw std::length_error("Empty Stack!");
|
||||||
}
|
}
|
||||||
--stackSize;
|
--stackSize;
|
||||||
if(stackSize < (int)(size/4)){
|
if(stackSize < (int)(size/4)){
|
||||||
|
@ -157,6 +139,4 @@ void StackVec<Data>::Clear(){
|
||||||
stackSize = 0;
|
stackSize = 0;
|
||||||
Elements = new Data[size];
|
Elements = new Data[size];
|
||||||
}
|
}
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
ulong stackSize = 0; // first empty cell
|
ulong stackSize = 0; // first empty cell and # of elements in the vector
|
||||||
using Vector<Data>::Elements;
|
using Vector<Data>::Elements;
|
||||||
using Vector<Data>::size; // dimension of the vector
|
using Vector<Data>::size; // dimension of the vector
|
||||||
|
|
||||||
|
|
|
@ -6,32 +6,6 @@
|
||||||
using namespace lasd;
|
using namespace lasd;
|
||||||
|
|
||||||
void menu(){
|
void menu(){
|
||||||
/*
|
|
||||||
!!! BUG !!!
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
Vector<int> v(5);
|
|
||||||
v[0] = 0;
|
|
||||||
v[1] = 1;
|
|
||||||
v[2] = 2;
|
|
||||||
v[3] = 3;
|
|
||||||
|
|
||||||
StackVec<int> sv;
|
|
||||||
sv.Push(0);
|
|
||||||
sv.Push(1);
|
|
||||||
sv.Push(2);
|
|
||||||
sv.Push(3);
|
|
||||||
|
|
||||||
StackVec<int> sv2(sv);
|
|
||||||
|
|
||||||
if(sv2 == v) std::cout<<"OK";
|
|
||||||
else std::cout<<"NO";
|
|
||||||
*/
|
|
||||||
|
|
||||||
QueueLst<int> q;
|
|
||||||
int a =3;
|
|
||||||
q.Enqueue(std::move(a));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue