Library 2

myTests completed
This commit is contained in:
Alessandro Ferro 2021-04-21 23:37:01 +02:00
parent c06eac8429
commit 9c17978640
3 changed files with 107 additions and 10 deletions

Binary file not shown.

View File

@ -85,29 +85,34 @@ void UseChosenType(DataStructure chosenDataStructure, DataType chosenDataType, I
if(chosenDataType == DataType::integer){ if(chosenDataType == DataType::integer){
StackVec<int> stckvec; StackVec<int> stckvec;
stckvec = generateRandomStackVecInt(); stckvec = generateRandomStackVecInt();
StackIntFunctions(stckvec); StackFunctions(stckvec);
} }
else if(chosenDataType == DataType::ffloat){ else if(chosenDataType == DataType::ffloat){
StackVec<float> stckvec; StackVec<float> stckvec;
stckvec = generateRandomStackVecFloat(); stckvec = generateRandomStackVecFloat();
StackFunctions(stckvec);
} }
else if(chosenDataType == DataType::sstring){ else if(chosenDataType == DataType::sstring){
StackVec<std::string> stckvec; StackVec<std::string> stckvec;
stckvec = generateRandomStackVecString(); stckvec = generateRandomStackVecString();
StackFunctions(stckvec);
} }
} }
else if(chosenImplementation == Implementation::list){ else if(chosenImplementation == Implementation::list){
if(chosenDataType == DataType::integer){ if(chosenDataType == DataType::integer){
StackLst<int> stcklst; StackLst<int> stcklst;
stcklst = generateRandomStackLstInt(); stcklst = generateRandomStackLstInt();
StackFunctions(stcklst);
} }
else if(chosenDataType == DataType::ffloat){ else if(chosenDataType == DataType::ffloat){
StackLst<float> stcklst; StackLst<float> stcklst;
stcklst = generateRandomStackLstFloat(); stcklst = generateRandomStackLstFloat();
StackFunctions(stcklst);
} }
else if(chosenDataType == DataType::sstring){ else if(chosenDataType == DataType::sstring){
StackLst<std::string> stcklst; StackLst<std::string> stcklst;
stcklst = generateRandomStackLstString(); stcklst = generateRandomStackLstString();
StackFunctions(stcklst);
} }
} }
} }
@ -116,35 +121,41 @@ void UseChosenType(DataStructure chosenDataStructure, DataType chosenDataType, I
if(chosenDataType == DataType::integer){ if(chosenDataType == DataType::integer){
QueueVec<int> queuevec; QueueVec<int> queuevec;
queuevec = generateRandomQueueVecInt(); queuevec = generateRandomQueueVecInt();
QueueFunctions(queuevec);
} }
else if(chosenDataType == DataType::ffloat){ else if(chosenDataType == DataType::ffloat){
QueueVec<float> queuevec; QueueVec<float> queuevec;
queuevec = generateRandomQueueVecFloat(); queuevec = generateRandomQueueVecFloat();
QueueFunctions(queuevec);
} }
else if(chosenDataType == DataType::sstring){ else if(chosenDataType == DataType::sstring){
QueueVec<std::string> queuevec; QueueVec<std::string> queuevec;
queuevec = generateRandomQueueVecString(); queuevec = generateRandomQueueVecString();
QueueFunctions(queuevec);
} }
} }
else if(chosenImplementation == Implementation::list){ else if(chosenImplementation == Implementation::list){
if(chosenDataType == DataType::integer){ if(chosenDataType == DataType::integer){
QueueLst<int> queuelist; QueueLst<int> queuelist;
queuelist = generateRandomQueueListInt(); queuelist = generateRandomQueueListInt();
QueueFunctions(queuelist);
} }
else if(chosenDataType == DataType::ffloat){ else if(chosenDataType == DataType::ffloat){
QueueLst<float> queuelist; QueueLst<float> queuelist;
queuelist = generateRandomQueueListFloat(); queuelist = generateRandomQueueListFloat();
QueueFunctions(queuelist);
} }
else if(chosenDataType == DataType::sstring){ else if(chosenDataType == DataType::sstring){
QueueLst<std::string> queuelist; QueueLst<std::string> queuelist;
queuelist = generateRandomQueueListString(); queuelist = generateRandomQueueListString();
QueueFunctions(queuelist);
} }
} }
} }
} }
template <typename T> template <typename T>
void StackIntFunctions(T& stk){ void StackFunctions(T& stk){
unsigned short int choice; unsigned short int choice;
do{ do{
std::cout<<std::endl<<std::endl; std::cout<<std::endl<<std::endl;
@ -163,7 +174,7 @@ void StackIntFunctions(T& stk){
std::cout<<std::endl; std::cout<<std::endl;
switch(choice){ switch(choice){
case 1: case 1:
PushInt(stk); Push(stk);
break; break;
case 2: case 2:
Pop(stk); Pop(stk);
@ -183,13 +194,87 @@ void StackIntFunctions(T& stk){
case 7: case 7:
Clear(stk); Clear(stk);
break; break;
case 8:
menu();
break;
} }
}while(choice!=9 && choice!=8); }while(choice!=9 && choice!=8);
} }
template <typename T> template <typename T>
void PushInt(T& stk){ void QueueFunctions(T& queue){
int element; unsigned short int choice;
do{
std::cout<<std::endl<<std::endl;
std::cout<<"Choose one of the following options:"<<std::endl;
std::cout<<"1. Inserimento di un elemento (Enqueue)"<<std::endl;
std::cout<<"2. Rimozione di un elemento (Dequeue)"<<std::endl;
std::cout<<"3. Rimozione con lettura (HeadNDequeue)"<<std::endl;
std::cout<<"4. Lettura non distruttiva (Head)"<<std::endl;
std::cout<<"5. Test di vuotezza"<<std::endl;
std::cout<<"6. Dimensione"<<std::endl;
std::cout<<"7. Clear Stack"<<std::endl;
std::cout<<"8. Vai indietro"<<std::endl;
std::cout<<"9. Esci"<<std::endl;
std::cin>>std::ws;
std::cin>>choice;
std::cout<<std::endl;
switch(choice){
case 1:
Enqueue(queue);
break;
case 2:
Dequeue(queue);
break;
case 3:
HeadNDequeue(queue);
break;
case 4:
Head(queue);
break;
case 5:
Empty(queue);
break;
case 6:
Size(queue);
break;
case 7:
Clear(queue);
break;
case 8:
menu();
break;
}
}while(choice!=9 && choice!=8);
}
template <template <typename...> class C, typename T>
void Enqueue(C<T>& queue){
T element;
std::cout<<"Element to enqueue: ";
std::cin>>std::ws;
std::cin>>element;
queue.Enqueue(element);
}
template <typename T>
void Dequeue(T& queue){
queue.Dequeue();
}
template <typename T>
void HeadNDequeue(T& queue){
std::cout<<"The head and dequeued element is "<<queue.HeadNDequeue();
}
template <typename T>
void Head(T& queue){
std::cout<<"The head is "<<queue.Head();
}
template <template <typename...> class C, typename T>
void Push(C<T>& stk){
T element;
std::cout<<"Element to push: "; std::cout<<"Element to push: ";
std::cin>>std::ws; std::cin>>std::ws;
std::cin>>element; std::cin>>element;
@ -213,7 +298,7 @@ void Top(T& stk){
template <typename T> template <typename T>
void Empty(T& stk){ void Empty(T& stk){
std::cout<<"Stack is "; std::cout<<"It is ";
stk.Empty()? std::cout<<"" : std::cout<<"not "; stk.Empty()? std::cout<<"" : std::cout<<"not ";
std::cout<<"empty"; std::cout<<"empty";
} }
@ -226,7 +311,7 @@ void Size(T& stk){
template <typename T> template <typename T>
void Clear(T& stk){ void Clear(T& stk){
stk.Clear(); stk.Clear();
std::cout<<"Stack has been cleared."; std::cout<<"It has been cleared.";
} }

View File

@ -36,10 +36,10 @@ lasd::StackVec<float> generateRandomStackVecFloat();
lasd::StackVec<std::string> generateRandomStackVecString(); lasd::StackVec<std::string> generateRandomStackVecString();
template <typename T> template <typename T>
void StackIntFunctions(T&); void StackFunctions(T&);
template <typename T> template <template <typename...> class C, typename T>
void PushInt(T&); void Push(C<T>&);
template <typename T> template <typename T>
void Pop(T&); void Pop(T&);
template <typename T> template <typename T>
@ -52,6 +52,18 @@ template <typename T>
void Size(T&); void Size(T&);
template <typename T> template <typename T>
void Clear(T&); void Clear(T&);
template <typename T>
void QueueFunctions(T&);
template <template <typename...> class C, typename T>
void Enqueue(C<T>&);
template <typename T>
void Dequeue(T&);
template <typename T>
void HeadNDequeue(T&);
template <typename T>
void Head(T&);
std::string generateRandomString(ulong); std::string generateRandomString(ulong);
ulong getDimension(); ulong getDimension();